diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..fdc8fcf --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,55 @@ +name: Publish to NPM + +on: + push: + branches: + - main + +permissions: + id-token: write # Required for npm provenance (OIDC) + contents: read + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Update npm + run: npm install -g npm@latest + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test + + - name: Build + run: npm run build + + - name: Check if version exists on npm + id: version-check + run: | + PACKAGE_NAME=$(node -p "require('./package.json').name") + LOCAL_VERSION=$(node -p "require('./package.json').version") + + # Check if this version already exists on npm + if npm view "${PACKAGE_NAME}@${LOCAL_VERSION}" version 2>/dev/null; then + echo "Version ${LOCAL_VERSION} already exists on npm. Skipping publish." + echo "should_publish=false" >> $GITHUB_OUTPUT + else + echo "Version ${LOCAL_VERSION} is new. Will publish." + echo "should_publish=true" >> $GITHUB_OUTPUT + fi + + - name: Publish to NPM + if: steps.version-check.outputs.should_publish == 'true' + run: npm publish --access=public --provenance diff --git a/DEPLOY.md b/DEPLOY.md index 0068be7..9d178f4 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -1,4 +1,26 @@ -# Deployment Commands +# Deployment -- `npm run build` -- `npm publish --access public` \ No newline at end of file +This package is automatically published to npm on every push to the `main` branch via GitHub Actions. + +## How to Deploy + +1. Update the version in `package.json` +2. Push/merge your changes to `main` +3. GitHub Actions will automatically: + - Run tests + - Build the package + - Publish to npm + +## Required Setup + +Add an `NPM_TOKEN` secret to your GitHub repository: +1. Create an access token at https://www.npmjs.com/settings/tokens +2. Go to your GitHub repo → Settings → Secrets and variables → Actions +3. Add a new secret named `NPM_TOKEN` with your npm token + +## Manual Deployment (if needed) + +```bash +npm run build +npm publish --access=public +``` diff --git a/README.md b/README.md index 2bf42ec..b829b4c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # SPARQ.AI Search Client -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7b750a903df8454bbe0747aa74b23d54)](https://www.codacy.com/app/naveensky/search-client-js?utm_source=github.com&utm_medium=referral&utm_content=searchtap/search-client-js&utm_campaign=Badge_Grade) -[![Build Status](https://travis-ci.org/searchtap/search-client-js.svg?branch=master)](https://travis-ci.org/searchtap/search-client-js) -[![npm](https://img.shields.io/npm/dm/@searchtap/search-client.svg)](https://www.npmjs.com/package/@searchtap/search-client) -[![NpmVersion](https://img.shields.io/npm/v/@searchtap/search-client.svg)](https://www.npmjs.com/package/@searchtap/search-client) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7b750a903df8454bbe0747aa74b23d54)](https://www.codacy.com/app/naveensky/search-client-js?utm_source=github.com&utm_medium=referral&utm_content=sparq/search-client-js&utm_campaign=Badge_Grade) +[![Build Status](https://travis-ci.org/sparq/search-client-js.svg?branch=master)](https://travis-ci.org/sparq/search-client-js) +[![npm](https://img.shields.io/npm/dm/@sparq/search-client.svg)](https://www.npmjs.com/package/@sparq/search-client) +[![NpmVersion](https://img.shields.io/npm/v/@sparq/search-client.svg)](https://www.npmjs.com/package/@sparq/search-client) -[SearchTap](https://www.searchtap.io/) is a subscription based hosted search solution for websites (eCommerce, Media and Publishing), mobile applications and enterprise software that delivers relevant results instantly. +[Sparq](https://www.sparq.ai/) is a subscription based hosted search solution for websites (eCommerce, Media and Publishing), mobile applications and enterprise software that delivers relevant results instantly. -Search Client is a lightweight search-only client that handles only the searches. It can be used in applications that require search access to their data and don't require the full blown client `@searchtap/client`. The Search Client library makes it easy to send requests and retrieve search results from the server for you. +Search Client is a lightweight search-only client that handles only the searches. It can be used in applications that require search access to their data and don't require the full blown client `@sparq/client`. The Search Client library makes it easy to send requests and retrieve search results from the server for you. ## Table of Contents @@ -50,26 +50,26 @@ Search Client is a lightweight search-only client that handles only the searches ##### Browser -`` +`` ##### NPM -`npm install @searchtap/search-client --save` +`npm install @sparq/search-client --save` ##### YARN -`yarn add @searchtap/search-client` +`yarn add @sparq/search-client` ## Quick Start ### Initialize the Search Client -To initiate, you will have to create a new search client which would require an **Application ID** and a **Search Token**. You can find both on your [SearchTap account](https://dashboard.searchtap.io/login). +To initiate, you will have to create a new search client which would require an **Application ID** and a **Search Token**. You can find both on your [Sparq account](https://app.sparq.ai/login). > Always use your search-only tokens to make search operations from public clients like browser or mobile apps. Do not use your admin tokens on public facing clients. ``` -import SearchClient from "@searchtap/search-client"; +import SearchClient from "@sparq/search-client"; var searchClient = new SearchClient(, ) ``` @@ -88,7 +88,7 @@ Look at the complete definitions for all methods available [here](#options) ### Search -You can initiate search by defining a text query and the collection id in the syntax below. Collection id can be found on your SearchTap account, every collection id is associated with a specific application. +You can initiate search by defining a text query and the collection id in the syntax below. Collection id can be found on your Sparq account, every collection id is associated with a specific application. ``` searchClient.search(, ) @@ -151,7 +151,7 @@ The default behaviour is to search on all fields. `.textFacets(...)` `[array, optional]` : Text facets to be retrieved. For each of the retrieved facets (eg. color; size; brand), the response will contain a list of facet values (red, blue; small, large; zara…) and associated count of records for that facet value. -> You would be require to configure facets on the SearchTap dashboard for the collection before fetching its data. If not configured, you would receive an error. +> You would be require to configure facets on the Sparq dashboard for the collection before fetching its data. If not configured, you would receive an error. The default behaviour is to not fetch any facet values. @@ -173,7 +173,7 @@ searchClient.textFacetFilters('Brand',['zara','tommy hilfiger']) `.numericFacets(...)` `[optional]`: Numeric facets as the name suggests, are facets with numeric values (eg. price, age). `.numericFacets` let's you define the ranges you want to show to the end user along with count of records in that range. You can use the same to create a histogram slider for your front-end UI. -> You would be require to configure facets on the SearchTap dashboard for the collection before fetching its data. If not configured, you would receive an error. +> You would be require to configure facets on the Sparq dashboard for the collection before fetching its data. If not configured, you would receive an error. The default behavior is to not fetch any numeric facet value. @@ -333,4 +333,4 @@ searchClient.typoTolerance(1) ## Getting Help -- **Need help?** Ask a question [here](https://github.com/searchtap/search-client-js/issues/new) +- **Need help?** Ask a question [here](https://github.com/sparq-ai/search-client-js/issues/new) diff --git a/package.json b/package.json index de2a7b9..8e3d472 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { - "name": "@searchtap/search-client", - "version": "2.0.0", + "name": "@sparq/search-client", + "version": "2.0.5", "keywords": [ "search", "search as you type", - "searchtap", + "sparq", "search client" ], - "description": "Search Client is a lightweight search-only client that handles searches at SearchTap platform.", + "description": "Search Client is a lightweight search-only client that handles searches at Sparq platform.", "main": "lib/index.min.js", "types": "lib/SearchClient.d.ts", "scripts": { @@ -15,8 +15,8 @@ "test": "NODE_ENV=test ./node_modules/mocha/bin/_mocha --full-trace --require ts-node/register --exit ./tests/**/*.spec.ts", "code-coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text ./node_modules/mocha/bin/_mocha --full-trace --require ts-node/register --exit ./tests/**/*.spec.ts && cat ./coverage/lcov.info | codacy-coverage && rm -rf ./coverage ./.nyc_output" }, - "author": "tech@searchtap.io", - "repository": "https://github.com/searchtap/search-client-js", + "author": "tech@sparq.ai", + "repository": "https://github.com/sparq-ai/search-client-js", "license": "MIT", "dependencies": { "axios": "^0.18.0"