Skip to content

Commit

Permalink
Feature: swell node http (#37)
Browse files Browse the repository at this point in the history
* switch to http-client + typescript rewrite

* prettier / lint

* fix import in test suite

* fix copyright

* fix version
  • Loading branch information
swellmike authored Oct 18, 2024
1 parent 195236f commit 44994e4
Show file tree
Hide file tree
Showing 26 changed files with 3,488 additions and 3,752 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": { "project": ["./tsconfig.json"] },
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
]
}
15 changes: 14 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
node_modules
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# build
/dist
/node_modules

# debug
/scratch

# typescript
*.tsbuildinfo

# eslint cache
.eslintcache
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.19.1
16.20.2
12 changes: 6 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License
MIT License

Copyright (c) 2018-2019 Swell Stores
Copyright (c) 2018 Swell Commerce Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 7 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,33 @@
## Connect

```javascript
const swell = require('swell-node');
const { swell } = require('swell-node');

swell.init('my-store', 'secret-key');
```

To connect to multiple stores in the same process, use `swell.createClient()`:

```javascript
const swell = require('swell-node');
const { swell } = require('swell-node');

const store1 = swell.createClient('my-store-1', 'secret-key-1');
const store2 = swell.createClient('my-store-2', 'secret-key-2');
const client1 = swell.createClient('my-store-1', 'secret-key-1');
const client2 = swell.createClient('my-store-2', 'secret-key-2');
```

## Usage

```javascript
try {
const products = await swell.get('/products', {
const { data } = await swell.get('/products', {
active: true
});
console.log(products);
console.log(data);
} catch (err) {
console.error(err);
console.error(err.message);
}
```

## Caching

This library provides in-memory caching enabled by default, using a version protocol that means you don't have to worry about stale cache. Records that don't change too frequently, such as products, will always return from cache when possible.

To disable caching behavior, use the option `cache: false`.

```javascript
swell.init('my-store', 'secret-key', {
cache: false,
});
```

## Documentation

This library is intended for use with the Swell Backend API: https://developers.swell.is/backend-api
Expand Down
4 changes: 0 additions & 4 deletions index.js

This file was deleted.

5 changes: 0 additions & 5 deletions jest.config.json

This file was deleted.

13 changes: 13 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Config } from 'jest';

const config: Config = {
clearMocks: true,
preset: 'ts-jest',
restoreMocks: true,
testEnvironment: 'node',
transform: {
'^.+\\.ts$': ['ts-jest', { diagnostics: { ignoreCodes: ['TS151001'] } }],
},
};

export default config;
Loading

0 comments on commit 44994e4

Please sign in to comment.