2.3.3

Types

Since this package has been designed using TypeScript, it inherently provides native support for it. 🖥

Axios

Here is the list of all axios interfaces and types used in this package:

  • AxiosInstance: used for the strapi.axios property.
  • AxiosRequestConfig: used for the axiosOptions in the Strapi Constructor and the custom request method.
  • Method: (which is a type) used for the parameter method in the custom request method.

Internal

Below is a list of all the custom types and interfaces used in this package.

You can easily use them by importing them.

import Strapi, { StrapiOptions } from "strapi-sdk-js"

const options: StrapiOptions = {
  url: "http://strapi-host/",
}

const strapi = new Strapi(options)

StrapiOptions

Options to configure a new Strapi SDK instance.

interface StrapiConfig {
  url?: string
  store?: StoreConfig
  axiosOptions?: AxiosRequestConfig
}

StoreConfig

Used for store configuration in Strapi SDK instanciation.

interface StoreConfig {
  key: string
  useLocalStorage?: boolean
  cookieOptions?: CookieAttributes
}

StrapiBaseRequestParams

Strapi query filters used in findOne, create, update, delete methods.

interface StrapiBaseRequestParams {
  fields?: Array<string>
  populate?: string | Array<string> | Record<string, unknown>
}

Check out the Strapi REST API documentation for more information.

StrapiRequestParams

Strapi query filters used in find methods.

interface StrapiRequestParams extends StrapiBaseRequestParams {
  sort?: string | Array<string>
  pagination?: PaginationByOffset | PaginationByPage
  filters?: Record<string, unknown>
  publicationState?: "live" | "preview"
  locale?: StrapiLocale
}

Check out the Strapi REST API documentation for more information.

PaginationByPage

With Strapi v4, results can be paginated. This type is used in StrapiRequestParams to paginate the results by page.

interface PaginationByPage {
  page: number
  pageSize: number
  withCount?: boolean
}

Check out the Strapi Pagination documentation for more information.

PaginationByOffset

With Strapi v4, results can be paginated. This type is used in StrapiRequestParams to paginate the results by offset.

interface PaginationByOffset {
  start: number
  limit: number
  withCount?: boolean
}

Check out the Strapi Pagination documentation for more information.

StrapiLocale

This type is used in StrapiRequestParams to retrieve content by locale.

type StrapiLocale = | "af" | "af-NA" | "af-ZA" | "agq" ...

Check out the Strapi i18n documentation for more information.

StrapiResponse<T>

Strapi v4 introduces a new response object. With this update, you have access to a data object (containing the response data itself) and a meta object (providing information about pagination, publication state, available locales, and more).

interface StrapiResponse<T> {
  data: T
  meta: Record<string, unknown>
}

Check out the Strapi Requests documentation for more information.

StrapiError

Errors are included in the response object with the error key and include information such as the HTTP status code, the name of the error, and additional information.

interface StrapiError {
  data: null
  error: {
    status: number
    name: string
    message: string
    details: Record<string, unknown>
  }
}

Check out the Strapi Error handling documentation for more information.

StrapiUser

Types of the user returned by Strapi. Returned by fetchUser method.

StrapiAuthProvider

Used for the provider parameter in the getProviderAuthenticationUrl and authenticateProvider methods.

type StrapiAuthProvider =
  | "github"
  | "facebook"
  | "google"
  | "cognito"
  | "twitter"
  | "discord"
  | "twitch"
  | "instagram"
  | "vk"
  | "linkedin"
  | "reddit"
  | "auth0"

Check out the Strapi Authentication Provider documentation for more information.

StrapiAuthenticationResponse

The return object type in the register, login, changePassword, resetPassword, forgotPassword, resetPassword and authenticateProvider methods.

interface StrapiAuthenticationResponse {
  user: Record<string, unknown>
  jwt: string
}

StrapiAuthenticationData

Used for the data parameter in the login method.

interface StrapiAuthenticationData {
  identifier: string
  password: string
}

StrapiRegistrationData

Used for the data parameter in the register method.

interface StrapiRegistrationData {
  username: string
  email: string
  password: string
}

StrapiChangePasswordData

Used for the data parameter in the changePassword method.

interface StrapiChangePasswordData {
  currentPassword: string
  password: string
  passwordConfirmation: string
}

StrapiForgotPasswordData

Used for the data parameter in the forgotPassword method.

interface StrapiForgotPasswordData {
  email: string
}

StrapiResetPasswordData

Used for the data parameter in the resetPassword method.

interface StrapiResetPasswordData {
  code: string
  password: string
  passwordConfirmation: string
}

StrapiEmailConfirmationData

Used for the data parameter in the sendEmailConfirmation method.

interface StrapiEmailConfirmationData {
  email: string
}