1.1.3 • Published 5 months ago

nest-snipe-sdk v1.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago
# Snipe SDK Service Documentation

The `SnipeSdkService` is a service for interacting with the Snipe API in a Nest.js application. It provides methods for signing up users, tracking events, retrieving token-related data, and managing referral programs. This documentation provides an overview of the service's methods and usage.

## Installation

To use the Snipe SDK service in your Nest.js application, you need to install it via npm:

```bash
npm install nest-snipe-sdk
```

Usage

  1. Import Module: In your Nest.js module, import the SnipeSdkModule and add it to the imports list. Configure it with your API key using SnipeSdkModule.forRoot('YOUR_API_KEY').
import { Module } from "@nestjs/common";
import { SnipeSdkModule } from "nest-snipe-sdk";

@Module({
  imports: [
    SnipeSdkModule.forRoot("YOUR_API_KEY"),
    // ...other imports
  ],
  // ...other module configurations
})
export class YourModule {}
  1. Inject the Service: In your service or controller, inject the SnipeSdkService for use in your methods.
import { Injectable } from "@nestjs/common";
import { SnipeSdkService } from "nest-snipe-sdk";

@Injectable()
export class YourService {
  constructor(private readonly snipeSdkService: SnipeSdkService) {}

  // Your methods using the Snipe SDK service
}

SnipeSdkService Methods

signUp

Sign up a user with a given hash. With optional signup_event for crediting the users on signup.

  • Parameters:

    • hash (string): The user's hash.
    • signup_event (string): The event_id for signup credit.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async signUp(hash: string, signup_event: string): Promise<string> {}

trackEvent

Track an event with optional parameters.

  • Parameters:

    • (object):
      • eventId (string): The event ID.
      • snipeUserId (string): The user ID.
      • transactionAmount (number, optional): The transaction amount.
      • partialPercentage (number, optional): The partial percentage.
      • debitTokens (array, optional): An array of debit tokens, each containing token_id and value.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async trackEvent(params: {
  eventId: string;
  snipeUserId: string;
  transactionAmount?: number | null;
  partialPercentage?: number | null;
  debitTokens?: { token_id: string; value: number }[] | null;
}): Promise<string> {}

getokenHistory

Get token history for a user.

  • Parameters:

    • (object):
      • snipeUserId (string): The user ID.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async getokenHistory(params: {
  snipeUserId: string;
}): Promise<string> {}

getokenHistoryWithFilter

Get token history with filters for a user.

  • Parameters:

    • (object):
      • snipeUserId (string): The user ID.
      • queryParameters (object):
        • page (number, optional): Pass an integer that defines the page number required for pagination.
        • page_size (number, optional): Pass an integer that defines the page size required for pagination.
        • transaction_type (string, optional): The type of transaction, which can be one of the following: 'credit', 'debit', 'both', 'pending', 'failed'.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

const filterResponse = await this.snipeSdkService.getokenHistoryWithFilter({
  snipeUserId: "snipeUserId123",
  queryParameters: {
    page: 2,
    page_size: 10,
    transaction_type: "credit",
  },
});

getokenDetails

Get token details for a user.

  • Parameters:

    • (object):
      • snipeUserId (string): The user ID.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async getokenDetails(params: {
  snipeUserId: string;
}): Promise<string> {}

getCoinData

Get coin data for a user.

  • Parameters:

    • (object):
      • snipeUserId (string): The user ID.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async getCoinData(params: {
  snipeUserId: string;
}): Promise<string> {}

getMultipliers

Retrieve all the multipliers for a user.

  • Parameters:

    • (object):
      • snipeUserId (string): The user ID.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async getMultipliers(params: {
  snipeUserId: string;
}): Promise<string> {}

Snipe Social Share (Referral Program)

createReferrer

Create a referral program for a user.

  • Parameters:

    • snipeUserId (string): The user ID.
    • referralProgramId (string): The referral program ID.
    • code (string): The code.
    • link (string): The link.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async createReferrer(
  snipeUserId: string,
  referralProgramId: string,
  code: string,
  link: string,
): Promise<string> {}

createReferee

Create a referee for a referral program.

  • Parameters:

    • snipeUserId (string): The user ID.
    • referralProgramId (string): The referral program ID.
    • code (string): The code.
    • link (string): The link.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async createReferee(
  snipeUserId: string,
  referralProgramId: string,
  code: string,
  link: string,
): Promise<string> {}

getReferralProgram

Get a referral program for a user.

  • Parameters:

    • snipeUserId (string): The user ID.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async getReferralProgram(
  snipeUserId: string,
): Promise<string> {}

getReferrer

Get details for a referrer.

  • Parameters:

    • snipeUserId (string): The user ID for the referrer.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async getReferrer(
  snipeUserId: string,
): Promise<string> {}

getReferee

Get details for a referee.

  • Parameters:

    • snipeUserId (string): The user ID for the referee.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async getReferee(
  snipeUserId: string,
): Promise<string> {}

getRefereeEvents

Get events completed and remaining for all the referees of a particular referee.

  • Parameters:

    • snipeUserId (string): The user ID for the referee.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async getRefereeEvents(
  snipeUserId: string,
): Promise<string> {}

getReferredUsers

Get users referred by a referrer.

  • Parameters:

    • snipeUserId (string): The user ID for the referrer.
  • Returns: A promise that resolves with the response.

  • Throws: An error if the API key is not initialized or if there's an error during the API call.

async getReferredUsers(
  snipeUserId: string,
): Promise<string> {}

Example Usage

import { Injectable } from "@nestjs/common";
import { SnipeSdkService } from "nest-snipe-sdk";

@Injectable()
export class YourService {
  constructor(private readonly snipeSdkService: SnipeSdkService) {}

  async test() {
    const eventResponse = await this.snipeSdkService.getReferredUsers(
      snipeUserId: "snipeUserId"
    );
    console.log(eventResponse);

    // Call other SnipeSdkService methods as needed
  }
}

Immersive Gamification - Streaks

fetchStreaks

Fetches the completed and remaining activities for a day of a user in a streak.

Function Signature

async fetchStreaks(
  snipeUserId: string,
): Promise<string> {}

Example Usage

import { Injectable } from "@nestjs/common";
import { SnipeSdkService } from "nest-snipe-sdk";

@Injectable()
export class YourService {
  constructor(private readonly snipeSdkService: SnipeSdkService) {}

  async test() {
    const Response = await this.snipeSdkService.fetchStreaks(
      snipeUserId: "snipeUserId"
    );
    console.log(Response);

    // Call other SnipeSdkService methods as needed
  }
}

Parameters

  • snipeUserId (string): The user ID for the referrer.

Returns

A promise that resolves with the response. The response object has the following structure:

{
  "data": {
    "type": "object",
    "value": {
      "user_id": "12345abcde",
      "activities": [
        {
          "activity": {
            "name": "Read Article",
            "description": "Read any article on our platform",
            "redirect_url": "https://example.com/articles",
            "image": "https://example.com/images/read.png",
            "event": {
              "name": "Sample Event",
              "description": "This is a sample event description.",
              "image": "https://example.com/sample-image.jpg",
              "constant_tokens": []
            },
            "uid": "2f8a502f-596f-4415-9f1d-e16dd7f4e3d4",
          },
          "is_completed": false
        },
        {
          "activity": {
            "name": "Watch Video",
            "description": "Watch any video tutorial",
            "redirect_url": "https://example.com/videos",
            "image": "https://example.com/images/watch.png",
            "event": {
              "name": "Sample Event",
              "description": "This is a sample event description.",
              "image": "https://example.com/sample-image.jpg",
              "constant_tokens": []
            },
            "uid": "5e8d1acd-0907-404f-b761-2245137e5234",
          },
          "is_completed": true
        }
      ],
      "streak_continue_count": 5,
      "continuous_streak_start_date": "2023-10-20T00:00:00.000Z",
      "resumed_day_count": 1,
      "allow_resume": true,
      "streak": "653f63a9850902e0eb4b2f19",
      "allow_missed": {
        "days": 2,
        "tokens": [{ "value": 20, "token_id": "650016a7eecb8c2bc282c262" }]
      }
    }
  },
  "meta": {
    "status": 200,
    "message": "OK",
    "timestamp": "2023-10-23T11:47:55.355Z"
  }
}

The data field contains the specific information about completed and remaining activities for the user for a particular day, which includes information like number of the days the streak has been maintained, and the start day of the streak. The meta field contains metadata, such as the HTTP status code, a brief status message, and the timestamp.

Throws

An error if the API key is not initialized or if there's an error during the API call.

This documentation provides detailed information about the structure of the response from the fetchStreaks function.

resumeStreaks

Resumes the streak for a specific referrer. This function allows the referrer to resume their streak under certain conditions, and the response can vary based on the situation. Here are the details of the function:

Function Signature

async resumeStreaks(
  snipeUserId: string,
  streak_id: string,
): Promise<object> {}

Example Usage

import { Injectable } from "@nestjs/common";
import { SnipeSdkService } from "nest-snipe-sdk";

@Injectable()
export class YourService {
  constructor(private readonly snipeSdkService: SnipeSdkService) {}

  async resumeStreak(snipeUserId: string, streakId: string) {
    try {
      const response = await this.snipeSdkService.resumeStreaks(
        snipeUserId,
        streakId
      );
      console.log(response);

      // Handle different responses as described in the documentation
    } catch (error) {
      console.error("Error while resuming streak:", error);
    }
  }
}

Parameters

  • snipeUserId (string): The user ID of the referrer.
  • streak_id (string): The streak ID that the referrer wants to resume.

Returns

A promise that resolves with the response. The response object has the following structure:

{
  "data": {
    "type": "object",
    "value": {
      "allow_resume": "boolean",
      "streak_resumed": "boolean"
    }
  },
  "meta": {
    "status": Number, // The HTTP status code (e.g., 200 for success).
    "message": String, // A brief status message.
    "timestamp": String, // A timestamp indicating when the response was generated.
  }
}
  • allow_resume (boolean): Indicates whether resuming the streak is allowed. If true, resuming is allowed; if false, resuming is not allowed.
  • streak_resumed (boolean): Indicates whether the streak was successfully resumed. If true, the streak was resumed; if false, the streak was not resumed.

Response Scenarios

The response can vary based on different scenarios:

  • If resuming is not allowed, the response will be: { "allow_resume": false, "streak_resumed": false }.
  • If resuming is allowed and the streak is successfully resumed, the response will be: { "allow_resume": true, "streak_resumed": true }.
  • If there is a problem in performing transactions or creating the resume document (could be because of invalid/not-matching tokens or events), the response will be: { "allow_resume": true, "streak_resumed": false }.

Throws

An error if the API key is not initialized or if there's an error during the API call.

This documentation provides detailed information about the resumeStreaks function, which allows referrers to resume their streaks based on certain conditions.

getStreakById

Retrieves the streak document for a specific streak ID.

Function Signature

async getStreakById(
  snipeUserId: string,
  streak_id: string,
): Promise<> {}

Example Usage

import { Injectable } from "@nestjs/common";
import { SnipeSdkService } from "nest-snipe-sdk";

@Injectable()
export class YourService {
  constructor(private readonly snipeSdkService: SnipeSdkService) {}

  async test() {
    const Response = await this.snipeSdkService.getStreakById(
      snipeUserId: "snipeUserId",
      streak_id: "streakId"
    );
    console.log(Response);

    // Call other SnipeSdkService methods as needed
  }
}

Parameters

  • snipeUserId (string): The user ID for the referrer.
  • streak_id (string): The ID of the streak document to retrieve.

Returns

A promise that resolves with the response. The response object will contain the specific information about the streak document associated with the provided streak_id. The structure of the response may vary depending on the API endpoint being accessed.

Throws

An error if the API key is not initialized or if there's an error during the API call.

This documentation provides a brief overview of the getStreakById function, which is used to fetch streak documents by providing a user's ID and a streak ID. For more details on the response structure.

1.1.3

5 months ago

1.1.1

5 months ago

1.1.0

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

7 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.1.2

5 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.12

6 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago