open-index/open-npm huggingface dataset:
npm package: @project-alf/sdk
Description: This is the SDK for the Project Alf. It's a collection of scripts and tools to interact with the ALF API and other services. This SDK is written in TypeScript and can be used in any Node.js and web project. Internally, it uses fetch() API to make HTTP req
Author: Project Alf
Latest version: 1.0.2

# Project-Alf-SDK

This is the SDK for the Project Alf. It's a collection of scripts and tools to interact with the ALF API and other services. This SDK is written in TypeScript and can be used in any Node.js and web project. Internally, it uses **[fetch() API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)** to make HTTP requests.

### Installing and development

To install the SDK, you can use the following:

```bash
 npm install @project-alf/sdk
```

or you can look on npm repository [here](https://www.npmjs.com/package/@project-alf/sdk)

### Usage

To use the SDK, you can import the SDK in your project and use it as follows. This shows how to use it standard way with await and async without nay callback and parameters.

```typescript
import { alf } from "@project-alf/sdk";

// Create a new instance of the ALF client with the origin and token
const alfClient = alf({
	origin: "https://allpha.project-alf.com",
	token: "<YOUR_TOKEN>",
});

// Get profile information
const profile = await alfClient.v1.profile();
```

### Making requests with parameters

Its also possible to parameterize the request with parameters. This is useful when you want make more specific requests. Current example fetches the first 10 products sorted by name in ascending order and also must contain the word "Name" in the name or description.

```typescript
const products = await alfClient.v1.products().list({
	offset: 0,
	limit: 10,
	sort: [{ field: "name", order: "asc" }],
	filter: "Name",
});
```

### Making requests with callbacks

You can also use callbacks to handle the request. This is useful when you want to show loading, error, and other messages to the user. The following example shows how to use callbacks to handle the request.

```typescript
const products = await alfClient.v1.products().list(
	{},
	{
		onStart: () => {
			//This will be called when the request starts
			console.log("Fetching products...");
		},
		onEnd: (data) => {
			//This will be called when the request ends and before promise resolves
			console.log("Products fetched", data);
		},
		onError: (error) => {
			//This will be called when the request fails
			console.error("Error fetching products", error);
		},
		onFatal: (error) => {
			//This will be called when the request fails and the error is fatal
			console.error("Fatal error fetching products", error);
		},
		onLoading: (loading) => {
			//This will be called when the request is loading state changes
			console.log("Loading products", loading);
		},
	},
);
```

### TypeScript support definition

The SDK is written in TypeScript and has full support for TypeScript. This means you can use the SDK in your TypeScript project and get full type checking and intellisense support.