diff --git a/.eslintrc b/.eslintrc index b09a76f..c4703f3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,12 +1,13 @@ { "root": true, "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint", "prettier"], + "plugins": ["@typescript-eslint", "prettier", "header"], "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], "rules": { "no-console": 1, "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": ["error"] + "@typescript-eslint/no-unused-vars": ["error"], + "header/header": [2, "./resources/license.header.js"] }, "ignorePatterns": ["dist", "node_modules", "*.js"] } diff --git a/README.md b/README.md index 5a5482b..f1b2201 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ docker run -p 3000:3000 arns-service The service leverages `warp-sdk` to retrieve, evaluate and cache contract state. To request a contract state, run: ```shell -curl localhost:3000/v1/contract/CONTRACT_ID +curl localhost:3000/v1/contract/${CONTRACT_ID} ``` e.g. @@ -49,6 +49,16 @@ e.g. curl localhost:3000/v1/contract/bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U ``` +For more advanced features of Warp caching and state evaluation (e.g. D.R.E nodes), refer to the [Warp] documentation. + +### LMDB + +This service uses the `warp-contracts-lmdb` for storing contract state. The LMDB is stored in the `./cache` directory. To clear the LMDB, run: + +```shell +rm -rf ./cache +``` + ### Evaluation Options By default, the service will load `Contract-Manifest` tags for state evaluation. @@ -84,9 +94,29 @@ yarn docker:integration ## Swagger -TODO +[Swagger] is used for endpoint documentation and testing. When running the service, you can load the Swagger UI in your browser at: + +```shell +http://localhost:3000/api-docs +``` + +For production, the Swagger UI is available at: + +```shell +https://api.arns.app/api-docs +``` ## Contributions - Build to interfaces - Integration tests take precedent over unit tests +- Use [conventional commits] for commit messages +- Use [prettier] for code formatting +- Use [eslint] for linting +- Use [swagger] for API documentation + +[Swagger]: https://swagger.io/ +[conventional commits]: https://www.conventionalcommits.org/en/v1.0.0/ +[prettier]: https://prettier.io/ +[eslint]: https://eslint.org/ +[Warp]: https://academy.warp.cc/docs/docs-intro diff --git a/docker-compose.yaml b/docker-compose.yaml index bc78ef7..3ef3c1b 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -14,9 +14,9 @@ services: NODE_VERSION_SHORT: ${NODE_VERSION_SHORT:-18} environment: NODE_ENV: ${NODE_ENV:-dev} - GATEWAY_HOST: arlocal - GATEWAY_PORT: 1984 - GATEWAY_PROTOCOL: http + GATEWAY_HOST: ${GATEWAY_HOST:-arlocal} + GATEWAY_PORT: ${GATEWAY_PORT:-1984} + GATEWAY_PROTOCOL: ${GATEWAY_PROTOCOL:-http} ports: - '3000:3000' diff --git a/package.json b/package.json index df764b9..5e4f322 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "commitlint": "^17.7.1", "dotenv": "^16.0.3", "eslint": "^8.42.0", + "eslint-plugin-header": "^3.1.1", "eslint-plugin-prettier": "^5.0.0", "husky": "^8.0.3", "mocha": "^10.2.0", diff --git a/resources/license.header.js b/resources/license.header.js new file mode 100644 index 0000000..4365e0f --- /dev/null +++ b/resources/license.header.js @@ -0,0 +1,16 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ diff --git a/src/api/graphql.ts b/src/api/graphql.ts index f39b418..b007b8f 100644 --- a/src/api/graphql.ts +++ b/src/api/graphql.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import Arweave from 'arweave'; import { ArNSInteraction } from '../types.js'; diff --git a/src/api/warp.ts b/src/api/warp.ts index 3682625..e3ae44f 100644 --- a/src/api/warp.ts +++ b/src/api/warp.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { EvaluationManifest, EvaluationOptions, Warp } from 'warp-contracts'; import { DEFAULT_EVALUATION_OPTIONS, diff --git a/src/app.ts b/src/app.ts index ddd81cd..390a2e6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import Koa from 'koa'; import router from './router'; import cors from '@koa/cors'; diff --git a/src/constants.ts b/src/constants.ts index cebeb01..5c2bc6c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { EvaluationOptions } from 'warp-contracts'; export const ARNS_CONTRACT_ID_REGEX = '([a-zA-Z0-9-_s+]{43})'; diff --git a/src/errors.ts b/src/errors.ts index 477457e..2679220 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { EVALUATION_TIMEOUT_MS } from './constants'; // TODO: we could put a prometheus metric here to help fine tune what our evaluation limit should be diff --git a/src/logger.ts b/src/logger.ts index 27bd34f..2333a35 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import winston, { format, transports } from 'winston'; const LOG_LEVEL = process.env.LOG_LEVEL ?? 'info'; diff --git a/src/middleware/arweave.ts b/src/middleware/arweave.ts index 7fbccd5..496cbc6 100644 --- a/src/middleware/arweave.ts +++ b/src/middleware/arweave.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { Next } from 'koa'; import { KoaContext } from '../types.js'; import Arweave from 'arweave'; diff --git a/src/middleware/errors.ts b/src/middleware/errors.ts index 2ae7520..8ab4862 100644 --- a/src/middleware/errors.ts +++ b/src/middleware/errors.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { KoaContext } from '../types'; import { Next } from 'koa'; import { BadRequestError, EvaluationError, NotFoundError } from '../types'; diff --git a/src/middleware/headers.ts b/src/middleware/headers.ts index a330bd1..3544e2e 100644 --- a/src/middleware/headers.ts +++ b/src/middleware/headers.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { Next } from 'koa'; import { KoaContext } from '../types'; diff --git a/src/middleware/index.ts b/src/middleware/index.ts index 94b3a59..1aae1d1 100644 --- a/src/middleware/index.ts +++ b/src/middleware/index.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ export * from './arweave'; export * from './headers'; export * from './logger'; diff --git a/src/middleware/logger.ts b/src/middleware/logger.ts index 19e545d..ff446b9 100644 --- a/src/middleware/logger.ts +++ b/src/middleware/logger.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { KoaContext } from '../types.js'; import { Next } from 'koa'; import crypto from 'crypto'; diff --git a/src/middleware/warp.ts b/src/middleware/warp.ts index ea28e9d..c139178 100644 --- a/src/middleware/warp.ts +++ b/src/middleware/warp.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { Next } from 'koa'; import { KoaContext } from '../types.js'; import { diff --git a/src/router.ts b/src/router.ts index 5b17aca..610e423 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import Router from '@koa/router'; import { ARNS_CONTRACT_FIELD_REGEX, diff --git a/src/routes/contract.ts b/src/routes/contract.ts index 0609379..8c1041c 100644 --- a/src/routes/contract.ts +++ b/src/routes/contract.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { Next } from 'koa'; import { diff --git a/src/routes/index.ts b/src/routes/index.ts index 0a4b76d..16ed862 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ export * from './contract'; export * from './prometheus'; export * from './wallet'; diff --git a/src/routes/prometheus.ts b/src/routes/prometheus.ts index f5c9f48..7834d63 100644 --- a/src/routes/prometheus.ts +++ b/src/routes/prometheus.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { Next } from 'koa'; import { KoaContext } from '../types.js'; import * as promClient from 'prom-client'; diff --git a/src/routes/wallet.ts b/src/routes/wallet.ts index b595a24..9f91d4d 100644 --- a/src/routes/wallet.ts +++ b/src/routes/wallet.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { Next } from 'koa'; import { BadRequestError, KoaContext } from '../types'; import { diff --git a/src/types.ts b/src/types.ts index 329d957..0fd911e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import winston from 'winston'; import Arweave from 'arweave'; import { DefaultState, ParameterizedContext } from 'koa'; diff --git a/tests/integration/routes.test.ts b/tests/integration/routes.test.ts index 2d23492..9509468 100644 --- a/tests/integration/routes.test.ts +++ b/tests/integration/routes.test.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import { describe } from 'mocha'; import { expect } from 'chai'; import axiosPackage from 'axios'; diff --git a/tests/integration/setup.test.ts b/tests/integration/setup.test.ts index 62e0062..8b156ce 100644 --- a/tests/integration/setup.test.ts +++ b/tests/integration/setup.test.ts @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ import Arweave from 'arweave'; import { JWKInterface } from 'arweave/node/lib/wallet'; import * as fs from 'fs'; diff --git a/yarn.lock b/yarn.lock index 8e5b04e..f88c82b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3201,6 +3201,11 @@ escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg== +eslint-plugin-header@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-header/-/eslint-plugin-header-3.1.1.tgz#6ce512432d57675265fac47292b50d1eff11acd6" + integrity sha512-9vlKxuJ4qf793CmeeSrZUvVClw6amtpghq3CuWcB5cUNnWHQhgcqy5eF8oVKFk1G3Y/CbchGfEaw3wiIJaNmVg== + eslint-plugin-prettier@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-5.0.0.tgz#6887780ed95f7708340ec79acfdf60c35b9be57a"