Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsdx → tsup, jest, eslint #2

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
overrides: [],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
rules: {}
};
40 changes: 40 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test and build PR
on: [pull_request]
jobs:
build:
name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['18.x', '20.x']
os: [windows-latest, macOS-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- name: Lint
run: npm run lint

- name: Test
run: npm run test -- --ci --maxWorkers=2

- name: Build
run: npm run build
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run test
npm run lint
30 changes: 6 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ To use this library, you must have a Terminus API key, and expose it on the envi

```js
import { fetchOne, search } from '@abcnews/terminus-fetch';
// We export fetchOne by default, as it's most commmonly used:
import fetchOne from '@abcnews/terminus-fetch';

// By default, we assume you want an Article docment from Core Media so you can pass a CMID:
// By default, we assume you want an Article document from Core Media so you can pass a CMID:

fetchOne(10736062, (err, doc) => {
if (!err) {
Expand Down Expand Up @@ -70,7 +68,7 @@ search({ limit: 1, source: 'mapi', service: 'triplej'})
.catch(err => console.error(err));
```

If your project's JS is currently executing in a page on `aus.aunty.abc.net.au`, requests will be made to Preview Terminus (`https://api-preview.terminus.abc-prod.net.au/api/v1/{teasable}content`), otherwise they'll be made to Live Terminus (`https://api.abc.net.au/terminus/api/v1/{teasable}content`).
If your project's JS is currently executing in a page on `*.aus.aunty.abc.net.au`, requests will be made to Preview Terminus (`https://api-preview.terminus.abc-prod.net.au/api/v2/{teasable}content`), otherwise they'll be made to Live Terminus (`https://api.abc.net.au/terminus/api/v2/{teasable}content`).

If you want to direct a single request to Live Terminus, regardless of the current execution domain, pass `force: "live"` as an option.

Expand Down Expand Up @@ -141,7 +139,7 @@ These are the same as `fetchOne`, only split across two options arguments.

### `getImages`

This takes an image document returned from terminus (Imge, ImageProxy or CustomImage doctypes) and returns
This takes an image document returned from terminus (Image, ImageProxy or CustomImage doctypes) and returns
a normalised object including available image renditions.

```ts
Expand All @@ -154,12 +152,7 @@ There is no guarantee that the returned object will contain the widths requested

Default for this argument is: `[160, 240, 480, 700, 940, 1400, 2150]`

The argument is optional and behaves slightly differently depending on whether the passed document is from a request to v1 or v2 of the API.

- _v1 documents_: this argument is completely ignored and the returned object will contain all available image sizes.
- _v2 documents_: rendition URLs for every available aspect ratio will be generated for every requested width.

_Note:_ There is also no guarantee about which aspect ratios are available for a given image.
_Note:_ There is no guarantee about which aspect ratios are available for a given image.

#### Returned object

Expand All @@ -184,20 +177,9 @@ declare type ImageRendition = {
};
```

There are a couple of gotchas in here related to image proxies. The `cmid` and `canonicalURL` properties will be those of the proxy, not the target image. While it's possible to return the ID of the proxied image from v1 documents, it's not on v2. So for the sake of standardisation, both will return the proxy ID and URL.

In v2 responses, it's possible that the binary URL a rendition points to is acctually smaller than the dimensions in the object. This is because small originals are never upscaled by the image resizer, but can still be requested. This situation is flagged by the `isUndersizedBinary` property.

## Developing

To run the `/example` project:

1. Copy `.env.example` to `.env` and add your Terminus API key
2. Start the development server with: `npm run example`
3. Visit `http:<machine_name>.aus.aunty.abc.net.au:1234`
4. Open the browser's development console
There are a couple of gotchas in here related to image proxies. The `cmid` and `canonicalURL` properties will be those of the proxy, not the target image.

Note: If you are sure you've added your Terminus API key to `.env` and the console is still warning you that the key is not present, delete parcel's `.cache` folder and re-start the dev server.
It's possible that the binary URL a rendition points to is actually smaller than the dimensions in the object. This is because small originals are never upscaled by the image resizer, but can still be requested. This situation is flagged by the `isUndersizedBinary` property.

### Releasing

Expand Down
3 changes: 0 additions & 3 deletions example/.npmignore

This file was deleted.

12 changes: 0 additions & 12 deletions example/index.html

This file was deleted.

75 changes: 0 additions & 75 deletions example/index.ts

This file was deleted.

6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
coverageReporters: ['text']
};
Loading
Loading