open-index/open-npm huggingface dataset:
npm package: @scandinavia/mock
Description: A simple package to mock data when the backend is busy.
Author: Abd Ul-Hameed Maree
Latest version: 0.0.5

# @scandinavia/mock

A simple package to mock data where is your backend is busy.

## Usage

```ts
import * as mock from '@scandinavia/mock';

// first name.
const randomMaleFirstName = mock.firstname('male');
const randomFemaleFirstName = mock.firstname('female');
const randomFirstName = mock.firstname();

// last name.
const randomLastName = mock.lastname();

// full name
const randomMaleFullName = mock.fullname('male');
const randomFullName = mock.fullname();

// username
const randomUsername = mock.username();

// word
const randomWord = mock.word();

// lorem/text
const randomTextWith100Words = mock.lorem(100);

// phone
const randomPhone = mock.phone();
const random12CharPhone = mock.phone(12);

// date
const rancomDateInTheFuture = mock.date(new Date(), new Date('2200'));
const rancomDateInThePast = mock.date();

// image
const randomSquareImageUrl = mock.image(200, 200);
const randomImageUrl = mock.date();

// avatar
const randomSmallAvatarUrl = mock.avatar(50);
const randomAvatarUrl = mock.date();

// number
const randomNumber = mock.number();
const randomFloatNumber = mock.number(true);
const randomNumberFrom10To100 = mock.number(10, 100);

// unique
const randomID = mock.unique();
const random4CharID = mock.unique(4);

// pick
const randomItem = mock.pick('item 1', 'item 2', 'item 3');
const randomValue = mock.pick(1, 2, 3);

// array
const randomArrayOfFullNamesLength20 = mock.array(() => mock.fullname(), 20);
```

this is the basic usage, let's see the real life application.

```ts
// in your model definition.
export type Product = {
  id: string;
  title: string;
  description: string;
  distributer: string;
  images: string[];
  price: number;
  category: 'tablet' | 'laptop' | 'mobile';
  discount: number;
  createdAt: Date;
};

export const mockProduct = (): Product => ({
  id: mock.unique(),
  title: mock.lorem(3),
  description: mock.lorem(20),
  distributer: mock.fullname(),
  images: mock.array(() => mock.image(200, 300), mock.number(1, 3)),
  price: mock.number(500, 4000),
  category: mock.pick('tablet', 'laptop', 'mobile'),
  discount: mock.number(0, 10),
  createdAt: mock.date(),
});

// in your products page.
const products = mock.array(mockProduct, mock.number(10, 30));

// in single product page.
const product = mockProduct();
```
npm package: @scandinavia/paypal-payment
Description: ### Usage
Latest version: 0.1.2

# PayPal Payment

### Usage

## Initialization
```
import { Module } from '@nestjs/common';
import { PaypalPaymentModule } from './paypal-payment.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import configurations from './configurations';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      expandVariables: true,
      load: [configurations],
    }),
    // Sync
    PaypalPaymentModule.register({
      clientId: process.env.PAYPAL_CLIENT_ID,
      clientSecret: process.env.PAYPAL_CLIENT_SECRET,
      environment: process.env.PAYPAL_ENVIRONMENT as ("sandbox" | "live")
    }),
    // Async
    PaypalPaymentModule.registerAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          ...configService.get('paypalModuleInterface'),
        };
      },
    }),
  ],
  controllers: [],
  providers: [],
})
export class AppModule {
}

```

## Inject & Use service
```
constructor(@InjectScandiniaviaPaypal() private paymentService: PaypalPaymentService) {}
```
## Initiate order

```
    const orderPayload: CreatePaypalOrderDto = {
      intent: 'CAPTURE',
      purchase_units: [
        {
          amount: {
            "currency_code": "USD",
            "value": "100.00"
          }
        }
      ]
    }
    const order = await initiateOrder(orderPayload, {
      Prefer: 'return=representation'
    });
```
Second param of `initiateOrder` is custom headers to control the response of initiating order
> Available headers: 
> The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager.
> * 'PayPal-Request-Id'?: string;
* 'PayPal-Partner-Attribution-Id'?: string;
* 'PayPal-Client-Metadata-Id'?: string;

> The preferred server response upon successful completion of the request. Value is:
 return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.
 return=representation. The server returns a complete resource representation, including the current state of the resource.
> * Prefer?: 'return=minimal' | 'return=representation';


## Get order

```
    const order = await paymentService.getOrderDetails(orderId);
```
## Update order

```
const order = // PayPal created order
paymentService.updateOrder(order.id, [
        {
          op: 'add',
          path: `/purchase_units/@reference_id=='${order.purchase_units[0].reference_id}'/shipping/address`,
          value: {
            "address_line_1": "123 Townsend St",
            "address_line_2": "Floor 6",
            "admin_area_2": "San Francisco",
            "admin_area_1": "CA",
            "postal_code": "94107",
            "country_code": "US"
          }
        }
      ]);
    })
    
 
```
npm package: @scandinavia/react-query
Description: A wrapper for react-query package, by adding more flexible and functionality
Author: Abd Ul-Hameed Maree
Latest version: 0.0.11

# @scandinavia/react-query

`@scandinavia/react-query` is a library that wrap [react-query](https://www.npmjs.com/package/react-query), by adding more flexible and functionality.

## Usage

implement it in your libs folder:

```ts
// libs/react-query

import axios from 'axios';
import { createReactQueryHelpers } from './index';
import { QueryClient } from 'react-query';

export const { createMutation, createQuery } = createReactQueryHelpers({
  // your axios instance with your global config.
  axiosInstance: axios.create(),

  // global function to handle error being thrown.
  handleError: err => {
    //
    throw err;
  },

  // global function to handle toast error.
  toast: err => alert(err.message),

  // global function to handle log error.
  log: err => console.error(err),
});

export const queryClient = new QueryClient();
```

now you can use it in your services:

```ts
// services/books

import { createQuery, createMutation, queryClient } from '../libs';
import { BookModel, CreateBookDto, UpdateBookDto } from '../models';
import { ResponseWithPagination } from '../types';

const URL = 'books';
const invalidateData = async () => {
  await queryClient.cancelQueries([URL, 'get']);
  await queryClient.invalidateQueries([URL, 'get']);
};

export const useGetBooks = (pagination: unknown) =>
  createQuery<ResponseWithPagination<BookModel>>(
    [URL, 'get', pagination],
    {
      method: 'get',
      url: URL,
      params: { pagination },
    },
    { keepPreviousData: true }
  );

export const useGetBook = (id?: unknown) =>
  createQuery<BookModel>(
    [URL, 'get', id],
    {
      method: 'get',
      url: `${URL}/${id}`,
    },
    { enabled: typeof id !== 'undefined' }
  );

export const useCreateBook = createMutation<BookModel, CreateBookDto>(
  [URL, 'post'],
  {
    method: 'post',
    url: URL,
  },
  {
    onMutate: invalidateData,
  }
);

export const useUpdateBook = (id?: unknown) =>
  createMutation<BookModel, UpdateBookDto>(
    [URL, 'put', id],
    {
      method: 'put',
      url: typeof id !== 'undefined' ? `${URL}/${id}` : URL,
    },
    {
      onMutate: invalidateData,
    }
  );

export const useDeleteBook = (id?: unknown) =>
  createMutation<BookModel>(
    [URL, 'delete', id],
    {
      method: 'delete',
      url: typeof id !== 'undefined' ? `${URL}/${id}` : URL,
    },
    {
      onMutate: invalidateData,
    }
  );
```

then you can use it in your component.