Skip to content

Commit 129ce8c

Browse files
committed
Convert project to TypeScript
Remove `SharpLayer` variable from all templates and documentation Use @types/aws-lambda where possible
1 parent 112262d commit 129ce8c

43 files changed

Lines changed: 4357 additions & 4927 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc

Lines changed: 0 additions & 47 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
deploy.yml
55
deploy.yaml
66
node_modules
7-
samconfig.toml
7+
samconfig.*
8+
!sam/samconfig.example.yaml
89
env.json
910
package.yml
1011
package.yaml
11-
samconfig.*
1212

1313
# NodeJS Build
1414
coverage

AGENTS.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Repository Guidelines
2+
3+
## Project Structure & Module Organization
4+
- `src/`: Lambda handler (`index.js`), helpers, resolvers, error handling, streaming.
5+
- `tests/`: Jest tests (`*.test.js`) and mocks.
6+
- `sam/`: AWS SAM templates.
7+
- `docs/`: Next.js site for documentation.
8+
- `scripts/`, `bin/`, `examples/`, `Dockerfile`, `Makefile`: tooling and examples.
9+
10+
## Build, Test, and Development Commands
11+
- `npm test`: run Jest (watch locally; single run on CI).
12+
- `npm run test-coverage`: Jest with coverage.
13+
- `npm run lint` / `npm run lint-fix`: ESLint check/fix for `src/*.js`.
14+
- `npm run build`: `sam build -t sam/template.yml --use-container`.
15+
- `npm run deploy` / `npm run deploy-guided`: deploy via SAM using `deploy.yml`.
16+
- Make targets (advanced): `make aws-package`, `make aws-publish` (requires Docker and `AWS_PROFILE`).
17+
18+
## Coding Style & Naming Conventions
19+
- JavaScript with 2‑space indentation, LF line endings, final newline (`.editorconfig`).
20+
- ESLint (Standard config). Key rules: semicolons required, object spacing, `prefer-const`, max lines per function warning.
21+
- Files in `src/` are small, single‑purpose modules. Tests live in `tests/` and end with `.test.js` (e.g., `helpers.test.js`).
22+
23+
## Testing Guidelines
24+
- Framework: Jest; coverage from `src/**/*.js`; Node test environment.
25+
- Name tests descriptively (e.g., `index.v2.test.js`, `resolvers.test.js`).
26+
- Run: `npm test` (watch) or `npm test -- --runInBand` for CI‑like runs. Keep PRs from decreasing coverage.
27+
28+
## Commit & Pull Request Guidelines
29+
- Branch from `main` (do not create `master`). Keep changes focused.
30+
- Commits: present‑tense summary + wrapped body; reference issues (e.g., “Closes #123”).
31+
- PRs must include: clear description, linked issues, tests, passing CI (CircleCI), and clean lint. Add screenshots for docs/UI changes when relevant.
32+
33+
## Security & Configuration Tips
34+
- Core env vars: `tiffBucket`, `resolverTemplate`, `preflight`, `corsAllow*`, `forceHost`, `pyramidLimit`, `pageThreshold`, `density`, `debugBorder`.
35+
- S3 access uses AWS SDK v3; grant least‑privilege IAM to the source bucket.

CONTRIBUTING.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,42 @@ be considered for inclusion in the code base and history of this repository.
8686
#### Prerequisites
8787

8888
- Some basic knowledge of AWS and [CloudFormation](https://aws.amazon.com/cloudformation/)
89-
- Requires the [SAM CLI](https://aws.amazon.com/serverless/sam/) and [AWS CLI](https://aws.amazon.com/cli/)
90-
- Building dependencies with the correct architecture on non-Linux systems requires [Docker](https://docs.docker.com/get-docker/).
89+
- [AWS CLI](https://aws.amazon.com/cli/)
90+
- [SAM CLI](https://aws.amazon.com/serverless/sam/)
91+
- [Docker](https://docs.docker.com/get-docker/)
92+
- The [make](https://www.gnu.org/software/make/) build tool (included with build tools on most UNIX-like operating systems)
9193

92-
#### Deploy
94+
#### Building and Deploying
9395

94-
The following instructions require you to `cd` into the correct directory for whichever flavor of the template you're using - `sam/standalone` for the Lambda-only version, or `sam/cloudfront` for the CloudFront-enabled version.
96+
The first time you run any of the build/package/publish/deploy commands, the `libvips`/`sharp` dependency layer will
97+
be built from source, which may take a while. But as long as you don't clear the Docker build cache (via
98+
`docker builder prune` or `docker system prune`), future calls should be nice and fast.
9599

96-
For iterative development, you may want to use [SAM Accelerate](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/accelerate.html) to keep the deployed stack in sync with local changes automatically.
100+
The file `sam/samconfig.example.yaml` contains examples of both `deploy` and `sync` configurations for command-line
101+
deployment and iterative development. Copy it to `sam/samconfig.yaml` and modify it to suit your configuration before
102+
running the commands below.
97103

98-
##### Using SAM
104+
##### Deploying
99105

100-
The easiest way to deploy is using the SAM guided command:
106+
```sh
107+
make deploy
108+
```
109+
110+
If you haven't created a [SAM configuration file](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html) per the above instructions, you will be guided through a series of prompts to provide the correct values, and then prompted to save the configuration file at the end before the stack is deployed.
111+
112+
If the stack deploys successfully, make note of the `Endpoint - IIIF Endpoint URL` output. You'll need this to test the API.
113+
114+
##### Iterative Development
101115

102116
```sh
103-
sam build --use-container
104-
sam deploy --guided
117+
make dev
105118
```
106119

107-
If successful, make note of the `Endpoint - IIIF Endpoint URL` output. You'll need this to test the API.
120+
This command deploys a stack and then watches the source for changes, which are synced automatically to the stack
121+
without all the CloudFormation overhead until you quit the watch process. This command does not have a guided
122+
deployment option, so it relies on the `default.sync` section of the SAM configuration file.
108123

109-
#### Test the API
124+
##### Testing the API
110125

111126
To test the API, you'll need an identifier that exists in your source bucket. Make a request for that identifier with:
112127

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ Previous versions of this application featured an optional [CloudFront](https://
1010

1111
While the CloudFront-enabled version of the application will remain available for the in the Serverless Application Repository for a time to provide an easy upgrade path for existing users, it is _strongly_ recommended that new deployments use the provided [documentation](https://samvera.github.io/serverless-iiif/docs/quick-start/infrastructure) and [examples](./examples) of [CloudFormation](https://aws.amazon.com/cloudformation/) templates and [Terraform](https://terraform.io/) manifests to deploy the standalone function as part of a larger application/infrastructure stack that defines its own CloudFront distribution.
1212

13-
### Breaking Changes from Version 4.x
13+
### Breaking Changes from Version 5.x
1414

15-
- The value of the `SharpLayer` variable must now be one of `INTERNAL`, `JP2`, or a valid Lambda layer ARN in the same region the
16-
application is being deployed in. The new default is `JP2`, which behaves the same as the former default (empty string). The new
17-
value, `INTERNAL`, uses the `sharp` and `libvips` dependencies compiled into the application itself.
15+
- The `SharpLayer` variable has been removed, and the `sharp` dependency (with JP2 support) bundled into the published
16+
package.
1817

1918
## Description
2019

deploy.yml.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ default:
2020
PixelDensity="0"
2121
Preflight="false"
2222
ResolverTemplate="%s.tif"
23-
SharpLayer=""
2423
SourceBucket=""
2524
image_repositories: []

eslint.config.mjs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { defineConfig, globalIgnores } from "eslint/config";
2+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
3+
import globals from "globals";
4+
import tsParser from "@typescript-eslint/parser";
5+
import path from "node:path";
6+
import { fileURLToPath } from "node:url";
7+
import js from "@eslint/js";
8+
import { FlatCompat } from "@eslint/eslintrc";
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
const compat = new FlatCompat({
13+
baseDirectory: __dirname,
14+
recommendedConfig: js.configs.recommended,
15+
allConfig: js.configs.all
16+
});
17+
18+
export default defineConfig([
19+
globalIgnores([
20+
"coverage/**/*",
21+
"docs/**/*",
22+
"node_modules/**/*",
23+
"build/**/*",
24+
]),
25+
{
26+
extends: compat.extends("plugin:@typescript-eslint/recommended"),
27+
28+
plugins: {
29+
"@typescript-eslint": typescriptEslint,
30+
},
31+
32+
languageOptions: {
33+
globals: {
34+
...Object.fromEntries(
35+
Object.entries(globals.browser).map(([key]) => [key, "off"])
36+
),
37+
...globals.node,
38+
...globals.jest,
39+
__DEV__: false,
40+
__TEST__: false,
41+
__PROD__: false,
42+
__COVERAGE__: false,
43+
},
44+
45+
parser: tsParser,
46+
},
47+
48+
rules: {
49+
"brace-style": [2, "1tbs"],
50+
"comma-dangle": [2, "never"],
51+
52+
indent: [
53+
"error",
54+
2,
55+
{
56+
SwitchCase: 1,
57+
},
58+
],
59+
60+
"key-spacing": 0,
61+
"max-len": [0, 120, 2],
62+
63+
"max-lines-per-function": [
64+
"warn",
65+
{
66+
max: 30,
67+
skipBlankLines: true,
68+
skipComments: true,
69+
},
70+
],
71+
72+
"no-unused-vars": [
73+
1,
74+
{
75+
vars: "all",
76+
args: "after-used",
77+
ignoreRestSiblings: false,
78+
argsIgnorePattern: "^_",
79+
},
80+
],
81+
82+
"no-var": 1,
83+
"object-curly-spacing": [2, "always"],
84+
85+
"prefer-const": [
86+
1,
87+
{
88+
destructuring: "any",
89+
ignoreReadBeforeAssign: true,
90+
},
91+
],
92+
93+
semi: [2, "always"],
94+
"space-in-parens": ["error", "never"],
95+
complexity: ["warn", 6],
96+
"@typescript-eslint/no-explicit-any": "warn",
97+
},
98+
},
99+
{
100+
files: ["tests/**/*.{ts,tsx}"],
101+
rules: {
102+
"max-lines-per-function": "off",
103+
complexity: "off",
104+
},
105+
},
106+
]);

extras/terraform/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ resource "aws_serverlessapplicationrepository_cloudformation_stack" "serverless_
3030
PixelDensity = var.pixel_density
3131
Preflight = var.preflight
3232
ResolverTemplate = var.resolver_template
33-
SharpLayer = var.sharp_layer
3433
SourceBucket = var.source_bucket
3534
}
3635
}

jest.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
module.exports = {
2-
collectCoverageFrom: ['src/**/*.js'],
2+
preset: 'ts-jest',
3+
transform: {
4+
'^.+\\.(ts|tsx)$': 'ts-jest',
5+
},
6+
collectCoverageFrom: ['src/**/*.ts'],
37
testPathIgnorePatterns: [
48
'<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]',
59
],
610
testEnvironment: 'node',
711
moduleDirectories: ['node_modules'],
12+
moduleFileExtensions: ['ts', 'js', 'json'],
813
moduleNameMapper: {
914
'^uuid$': require.resolve('uuid'),
1015
},

0 commit comments

Comments
 (0)