# `scripts-product-staging`

Scripts for use with bulk sessions, or products that have been "staged" before ingestion.

## Setup

```sh
curl -fsSL https://bun.com/install | bash
bun install
```

### Environment

Copy the shadow file to create your local `.env`:

```sh
cp .env.shadow .env
```

Fill in the database credentials in `.env`. See the [RDS Cluster and User Creation Self-Service](https://www.notion.so/RDS-Cluster-and-User-Creation-Self-Service-55af0b6e65a44d21a8d0702059cbdaab) guide for obtaining credentials. You will want a read-only user in the production `ows-product-staging` database.

### AWS Access

Authenticate with AWS using [awsume](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f) before running the CLI:

```sh
awsume prod
```

## Commands

### `bun export`

```sh
$ bun export --help
$ bun run export.ts --help
Usage: export [options]

CLI for exporting bulk session spreadsheet and asset data.

Dumps the spreadsheet and assets (if --assets is specified) to the output directory,
in subdirectories labelled by bulk session ID.

Options:
  --bulk-session-id <id>  Bulk session UUID
  --dir <path>            Output directory (default: "~/Downloads/bulk-exports")
  --assets                Include assets
  --dummy-assets          Generate dummy assets instead of downloading from S3
  --no-ids                Remove UPC/ISRC identifiers from the spreadsheet
  --random-codes          Randomize project and product codes in the spreadsheet
  -h, --help              display help for command
```

Runs the CLI. Requires `--bulk-session-id`. Downloads the spreadsheet for the given session and optionally its asset files.

```sh
# Download spreadsheet only
bun export --bulk-session-id 123e4567-e89b-12d3-a456-426614174000

# Download spreadsheet to a custom directory
bun export --bulk-session-id 123e4567-e89b-12d3-a456-426614174000 --dir ./output

# Download spreadsheet and all assets
bun export --bulk-session-id 123e4567-e89b-12d3-a456-426614174000 --assets

# Download spreadsheet and create dummy assets for testing
bun export --bulk-session-id 123e4567-e89b-12d3-a456-426614174000 --dummy-assets

# Strip UPC and ISRC to avoid ones that are potentially already in use
bun export --bulk-session-id 123e4567-e89b-12d3-a456-426614174000 --no-ids

# Replace product code and project code to avoid ones that are potentially already in use
bun export --bulk-session-id 123e4567-e89b-12d3-a456-426614174000 --random-codes
```

### `bun fmt`

Formats and auto-fixes all source files using [Biome](https://biomejs.dev/).

```sh
bun fmt
```

### `bun lint`

Runs the TypeScript compiler (`tsc --noEmit`) followed by Biome's linter and import sorting checks.

```sh
bun lint
```

### `bun test:unit`

Runs all unit tests with [`vitest`](https://vitest.dev/).

```sh
bun test:unit
```

### `bun docker:unit-lint`

Runs unit tests and linting inside a Docker container (linux/amd64). Builds the `unit-lint` target from the Dockerfile and exits with its exit code.

```sh
bun docker:unit-lint
```
