1.0.1 • Published 2 years ago

shopify-nestjs v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Nestjs shopify client

Community libarary that provides Shopify clients for NestJS applications.
It wraps the official shopify-node-api library in nestjs modules and services.

Table of Contents


How to use

Installing Dependencies

First you neeed to install all peer dependencies

  • @shopify/shopify-api— official shopify library
  • shopify-nestjs— this library
  • @nestjs/common— should be installed by default
$ npm install shopify-nestjs @shopify/shopify-api
$ yarn add shopify-nestjs @shopify/shopify-api
$ pnpm install shopify-nestjs @shopify/shopify-api

Import the ShopifyModule to you App module

Go to your app module and import the ShopifyModule using forRoot or forRootAsync

@Module({
    ...
    imports: [
        ...
        ShopifyModule.forRootAsync({
            ...
            useFactory: () => {
                    return {
                        IS_EMBEDDED_APP: false,
                        API_KEY: '82b1fe5a389dceb04b3a325fe69dea0c',
                        API_SECRET_KEY: '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',
                        HOST_NAME: 'host.example.com',
                        API_VERSION: ApiVersion.October20,
                        SCOPES: ['read_analytics', 'read_content', 'write_content'],
                        SHOP: 'your-shop-name',
                        PRIVATE_APP_STOREFRONT_ACCESS_TOKEN: '5f6032684f51c721c70f065dd9dedb17',
                    }
                }
            ...
    }),
        ...
    ]
    ...
})
@Module({
    ...
    imports: [
        ...
        ShopifyModule.forRoot({
            ...
            IS_EMBEDDED_APP: false,
            API_KEY: '82b1fe5a389dceb04b3a325fe69dea0c',
            API_SECRET_KEY: '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',
            HOST_NAME: 'host.example.com',
            API_VERSION: ApiVersion.October20,
            SCOPES: ['read_analytics', 'read_content', 'write_content'],
            SHOP: 'your-shop-name',
            PRIVATE_APP_STOREFRONT_ACCESS_TOKEN: '5f6032684f51c721c70f065dd9dedb17',
            ...
    }),
        ...
    ]
    ...
})

Import Clients

You can import each client when you need it using forFeature

...
import { ShopifyRestClientModule } from "shopify-nestjs"
...
@Module({
    ...
    imports: [
        ...
        ShopifyRestClientModule.forFeature()
        ...
    ]
    ...
})

You can also import all clients and use them across your application using ShopifyClientsModule.forRoot in your App module

...
import { ShopifyClientsModule } from "shopify-nestjs"
...
@Module({
    ...
    imports: [
        ...
        ShopifyClientsModule.forRoot()
        ...
    ]
    ...
})

Injecting and using clients

Once a client is available in you module you can inject it directly and use it each client extends the shopify official library client so you can use it as documented The official library readme.

...
import { ShopifyRestClient, ShopifyGraphqlClient, ShopifyStorefrontClient } from "shopify-nestjs"
...
  constructor(
    ...
    private _restClient: ShopifyRestClient,
    private _graphqlClient: ShopifyGraphqlClient,
    private _storefrontClient: ShopifyStorefrontClient,
    ...
  ) {}