-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,146 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
# Starter Kitty | ||
|
||
Common app components that are safe-by-default. | ||
Starter Kitty is a collection of common utilities and packages for JavaScript projects. It is designed to provide sensible defaults for common tasks, such as file system operations and input validation. | ||
|
||
## Why `starter-kitty`? | ||
|
||
Application security is hard. There are often many ways to get it wrong, and it's easy to make mistakes when you're trying to ship features quickly. This package provides a set of components that are safe-by-default, so you can focus on building your app without worrying about common security footguns. | ||
|
||
## Documentation | ||
|
||
Please refer to the [documentation website](https://kit.open.gov.sg/) for detailed API documentation and usage examples. | ||
|
||
## Packages | ||
|
||
- [`@opengovsg/starter-kitty-fs`](./packages/safe-fs/): Safe file system operations. | ||
- [`@opengovsg/starter-kitty-validators`](./packages/validators/): Common input validators. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Examples | ||
|
||
- [`@opengovsg/starter-kitty-validators`](./validators.md): Common input validators. | ||
- [`@opengovsg/starter-kitty-fs`](./safe-fs.md): Safe-by-default `fs` wrapper. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# @opengovsg/starter-kitty-fs | ||
|
||
## Installation | ||
|
||
```bash | ||
npm i --save @opengovsg/starter-kitty-fs | ||
``` | ||
|
||
## Usage | ||
|
||
```javascript | ||
import safeFs from '@opengovsg/starter-kitty-fs' | ||
|
||
const fs = safeFs('/app/content') | ||
|
||
// Writes to /app/content/hello.txt | ||
fs.writeFileSync('hello.txt', 'Hello, world!') | ||
|
||
// Tries to read from /app/content/etc/passwd | ||
fs.readFileSync('../../etc/passwd') | ||
``` | ||
|
||
The interfaces for all `fs` methods are the exact same as the built-in `fs` module, but if a `PathLike` parameter is given, | ||
it will be normalized, stripped of leading traversal characters, then resolved relative to the base directory passed to `safeFs`. | ||
|
||
This guarantees that the resolved path will always be within the base directory or its subdirectories. | ||
|
||
For example, if the base directory is `/app/content`: | ||
|
||
- `hello.txt` resolves to `/app/content/hello.txt` | ||
- `../../etc/passwd` resolves to `/app/content/etc/passwd` | ||
- `/etc/passwd` resolves to `/app/content/etc/passwd` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## API Report File for "@opengovsg/starter-kitty-fs" | ||
|
||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
```ts | ||
|
||
/// <reference types="node" /> | ||
|
||
import * as fs from 'node:fs'; | ||
|
||
// @public | ||
const safeFs: (basePath?: string) => typeof fs; | ||
export default safeFs; | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"extends": ["opengovsg"], | ||
"ignorePatterns": ["dist/**/*", "vitest.config.ts", "vitest.setup.ts"], | ||
"plugins": ["import", "eslint-plugin-tsdoc"], | ||
"rules": { | ||
"import/no-unresolved": "error", | ||
"tsdoc/syntax": "error" | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "**/tsconfig.json" | ||
}, | ||
"settings": { | ||
"import/parsers": { | ||
"@typescript-eslint/parser": [".ts", ".tsx"] | ||
}, | ||
"import/resolver": { | ||
"typescript": { | ||
"alwaysTryTypes": true, | ||
"project": "**/tsconfig.json" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Config file for API Extractor. For more info, please visit: https://api-extractor.com | ||
*/ | ||
{ | ||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
|
||
"extends": "../../api-extractor.json", | ||
|
||
/** | ||
* (REQUIRED) Specifies the .d.ts file to be used as the starting point for analysis. API Extractor | ||
* analyzes the symbols exported by this module. | ||
* | ||
* The file extension must be ".d.ts" and not ".ts". | ||
* | ||
* The path is resolved relative to the folder of the config file that contains the setting; to change this, | ||
* prepend a folder token such as "<projectFolder>". | ||
* | ||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName> | ||
*/ | ||
"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@opengovsg/starter-kitty-fs", | ||
"version": "1.2.3", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc && tsc-alias", | ||
"build:report": "api-extractor run --local --verbose", | ||
"build:docs": "api-documenter markdown --input-folder ../../temp/ --output-folder ../../apps/docs/api/", | ||
"lint": "eslint \"**/*.{js,jsx,ts,tsx}\" --cache", | ||
"test": "vitest", | ||
"ci:report": "api-extractor run --verbose" | ||
}, | ||
"devDependencies": { | ||
"@swc/core": "^1.6.13", | ||
"@types/node": "^18.19.47", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
"@typescript-eslint/parser": "^6.0.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-opengovsg": "^3.0.0", | ||
"eslint-config-prettier": "^8.6.0", | ||
"eslint-import-resolver-typescript": "^3.6.1", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
"eslint-plugin-tsdoc": "^0.3.0", | ||
"memfs": "^4.11.1", | ||
"prettier": "^2.8.4", | ||
"tsc-alias": "^1.8.10", | ||
"tsup": "^8.1.0", | ||
"typescript": "^5.4.5", | ||
"vitest": "^2.0.2" | ||
} | ||
} |
Oops, something went wrong.