Skip to content

Latest commit

 

History

History
441 lines (338 loc) · 36.7 KB

File metadata and controls

441 lines (338 loc) · 36.7 KB

Contexts

Overview

Available Operations

create

Create a new context with the specified type, id, and data. Returns 409 if context already exists. type and id are required fields, data is optional, if the context already exists, it returns the 409 response

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.contexts.create({
    type: "tenant",
    id: "org-acme",
    data: {
      "tenantName": "Acme Corp",
      "region": "us-east-1",
      "settings": {
        "theme": "dark",
      },
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { contextsCreate } from "@novu/api/funcs/contextsCreate.js";

// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const res = await contextsCreate(novu, {
    type: "tenant",
    id: "org-acme",
    data: {
      "tenantName": "Acme Corp",
      "region": "us-east-1",
      "settings": {
        "theme": "dark",
      },
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("contextsCreate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
createContextRequestDto components.CreateContextRequestDto ✔️ N/A
idempotencyKey string A header for idempotency purposes
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.ContextsControllerCreateContextResponse>

Errors

Error Type Status Code Content Type
errors.ErrorDto 414 application/json
errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
errors.ValidationErrorDto 422 application/json
errors.ErrorDto 500 application/json
errors.SDKError 4XX, 5XX */*

list

Retrieve a paginated list of all contexts, optionally filtered by type and key pattern. type and id are optional fields, if provided, only contexts with the matching type and id will be returned. search is an optional field, if provided, only contexts with the matching key pattern will be returned. Checkout all possible parameters in the query section below for more details

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.contexts.list({
    limit: 10,
    id: "tenant-prod-123",
    search: "tenant",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { contextsList } from "@novu/api/funcs/contextsList.js";

// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const res = await contextsList(novu, {
    limit: 10,
    id: "tenant-prod-123",
    search: "tenant",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("contextsList failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.ContextsControllerListContextsRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.ContextsControllerListContextsResponse>

Errors

Error Type Status Code Content Type
errors.ErrorDto 414 application/json
errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
errors.ValidationErrorDto 422 application/json
errors.ErrorDto 500 application/json
errors.SDKError 4XX, 5XX */*

update

Update the data of an existing context. type and id are required fields, data is required. Only the data field is updated, the rest of the context is not affected. If the context does not exist, it returns the 404 response

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.contexts.update({
    id: "<id>",
    type: "<value>",
    updateContextRequestDto: {
      data: {
        "tenantName": "Acme Corp",
        "region": "us-east-1",
        "settings": {
          "theme": "dark",
        },
      },
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { contextsUpdate } from "@novu/api/funcs/contextsUpdate.js";

// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const res = await contextsUpdate(novu, {
    id: "<id>",
    type: "<value>",
    updateContextRequestDto: {
      data: {
        "tenantName": "Acme Corp",
        "region": "us-east-1",
        "settings": {
          "theme": "dark",
        },
      },
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("contextsUpdate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.ContextsControllerUpdateContextRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.ContextsControllerUpdateContextResponse>

Errors

Error Type Status Code Content Type
errors.ErrorDto 414 application/json
errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
errors.ValidationErrorDto 422 application/json
errors.ErrorDto 500 application/json
errors.SDKError 4XX, 5XX */*

retrieve

Retrieve a specific context by its type and id. type and id are required fields, if the context does not exist, it returns the 404 response

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.contexts.retrieve("<id>", "<value>");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { contextsRetrieve } from "@novu/api/funcs/contextsRetrieve.js";

// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const res = await contextsRetrieve(novu, "<id>", "<value>");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("contextsRetrieve failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
id string ✔️ Context ID
type string ✔️ Context type
idempotencyKey string A header for idempotency purposes
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.ContextsControllerGetContextResponse>

Errors

Error Type Status Code Content Type
errors.ErrorDto 414 application/json
errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
errors.ValidationErrorDto 422 application/json
errors.ErrorDto 500 application/json
errors.SDKError 4XX, 5XX */*

delete

Delete a context by its type and id. type and id are required fields, if the context does not exist, it returns the 404 response

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.contexts.delete("<id>", "<value>");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { contextsDelete } from "@novu/api/funcs/contextsDelete.js";

// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const res = await contextsDelete(novu, "<id>", "<value>");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("contextsDelete failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
id string ✔️ Context ID
type string ✔️ Context type
idempotencyKey string A header for idempotency purposes
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.ContextsControllerDeleteContextResponse>

Errors

Error Type Status Code Content Type
errors.ErrorDto 414 application/json
errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
errors.ValidationErrorDto 422 application/json
errors.ErrorDto 500 application/json
errors.SDKError 4XX, 5XX */*