# Retrieve the private historical Sales bundle

Start at [the catalog](../catalog.json): `dataBank.salesBundle` describes the
historical companion to the private bank, and the Sales recipe selects it with
`bundleId`. Reports owns discovery and instructions. `master_planning` owns the
release, deterministic export, validation and Sales calculations. This is an
ordinary private JSON file in Google Drive, not a native Sheet, public data
endpoint or Reports aggregation service. A remote consumer does not need a
sibling checkout to download the prepared export.

## Availability and evidence

| Status | Meaning |
| --- | --- |
| `local_only` | Prepared export; no provisioned remote file |
| `configured` | Private file and intended identity's reader access configured; remote acceptance still pending |
| `remotely_verified` | Authorized download, integrity/content validation and unauthorized-denial tests passed through the actual remote interface |
| `unavailable` | File absent, revoked or inaccessible; report the observed reason |

Current evidence supports **`configured`**, as of November 10, 2026. The owner
provisioned the private JSON for release `20260907-20260927-29aba3d42a411b8a`.
Actual connected Drive raw download, independently trusted SHA-256 verification
and the source-owned validator passed. An anonymous request to the actual Drive
media endpoint was denied with HTTP 403. Denial to a valid ungranted Google
identity remains untested, so this is **not `remotely_verified`**. The connected
identity is the file owner; metadata listed only that owner's permission. No
separate reader grant or distribution of owner credentials was needed. Owner-side
local unit tests remain reported as passed, not independently rerun here.
Status is separate from the
`square.market_events` adapter status and from any previous local source review.
Changing a status requires dated evidence; documentation or a mock test cannot
establish remote acceptance. A failed discovery search alone does not prove the
file is absent from all Drive accounts.

## Owner provisioning

The owner uses `master_planning/docs/sales-bundle-access.md` and its existing
`scripts/sales_bundle.py` for the authoritative export, validation and download
options. Those private files are not included in Reports; do not guess CLI flags.
The owner must:

1. Validate the already prepared, content-addressed `.json` export against its
   trusted expected SHA-256. Upload those exact bytes as a **private binary file**
   (ordinary stored JSON, preferably `application/json`), without conversion to a
   Google Doc or Sheet, reformatting or re-exporting it.
2. Keep **General access: Restricted**. Use a location without broad inherited
   access; verify effective permissions. Grant **Viewer** (`reader`) access only
   to the intended agent Google identity in addition to the owner. Do not enable
   domain, public or anyone-with-link access or broaden existing folder access.
3. Ensure that identity has Google OAuth authorization supporting Drive downloads.
   Existing Sheets access alone does not establish that capability. Use the
   normal private credential/connector provisioning process; never distribute
   owner credentials or service-account keys, or ask for secret tokens in chat.
4. Supply the uploaded file link/file ID and **trusted expected hash privately**,
   together with the pinned release ID, period and source-owned validation/schema
   instructions. The content-addressed filename contains the hash too: keep that
   filename in the private handoff. A hash taken only from the downloaded file or
   its name is not an independent trust anchor. Verify the handoff refers to the
   prepared bundle named by the owner, not a newly calculated replacement.
5. Record provisioning evidence privately. Only then describe it as `configured`.
   Complete the remote tests below before using `remotely_verified`.

Reports must never contain the bundle, business records, runtime catalog, actual
file ID/download link, expected hash, private configuration or tokens in public
files, browser code, Git or logs. Keep downloads and detailed receipts in a
private working directory outside this checkout and its served tree.

## Authenticated download and integrity

1. Discover the Sales recipe and this contract from Reports. Check availability;
   at `local_only`, the remaining step is owner upload and private access handoff.
   Ask for the uploaded link only after a file has actually been provisioned and
   its ID cannot be resolved privately. Do not invent a file ID or treat a search
   result as proof of authorization.
2. Use the intended Google identity, with reader permission on that file and
   OAuth authorization supporting Drive downloads. The supported interface is:

   ```http
   GET https://www.googleapis.com/drive/v3/files/{file_id}?alt=media
   Authorization: Bearer <Google OAuth access token>
   ```

   Drive read/download tools may implement this without exposing a token. Inspect
   metadata first to confirm an ordinary stored JSON file. With the connected
   Drive tool, request `fetch(url=<private file link>, download_raw_file=True,
   include_base64=False)` and materialize its authenticated `file_uri` privately.
   Require the complete original bytes; readable text, a preview or native
   Workspace export is not acceptance evidence. Do not request inline base64.
   Tool availability does not prove the identity can download this file. If bytes cannot be materialized
   and hashed, report that capability gap and use the source-owned downloader in
   an authorized private runtime. Never extract connector credentials.
3. If using the REST interface directly, reuse the source-owned downloader when
   available. An equivalent bounded transport/integrity check is shown below;
   it does no normalization or aggregation. Disable tracing and verbose/debug
   logging. An owner-provisioned private curl config contains only the `url` for
   the interface above and the authorization `header`; the expected SHA-256 is
   in a separate trusted private file. Neither contains shell commands. Paths
   below must be supplied privately, outside Reports. No secret appears in command
   arguments. Run in a shell that stops on failure:

   ```sh
   set -eu
   umask 077
   : "${SALES_BUNDLE_PRIVATE_DIR:?existing private directory required}"
   : "${SALES_BUNDLE_CURL_CONFIG:?private URL/header config required}"
   : "${SALES_BUNDLE_SHA256_FILE:?trusted private expected hash file required}"
   export SALES_BUNDLE_PRIVATE_DIR SALES_BUNDLE_SHA256_FILE
   response_code=$(curl --disable --config "$SALES_BUNDLE_CURL_CONFIG" \
     --proto '=https' --silent --fail --max-time 60 --max-filesize 52428800 \
     --output "$SALES_BUNDLE_PRIVATE_DIR/sales-bundle.json" --write-out '%{http_code}')
   test "$response_code" = 200
   python3 - <<'PY'
   import hashlib
   import hmac
   import os
   from pathlib import Path
   import re
   expected = Path(os.environ['SALES_BUNDLE_SHA256_FILE']).read_text().strip()
   if not re.fullmatch(r'[0-9a-f]{64}', expected):
       raise SystemExit('Invalid private expected hash; stop')
   body = (Path(os.environ['SALES_BUNDLE_PRIVATE_DIR']) / 'sales-bundle.json').read_bytes()
   if not hmac.compare_digest(hashlib.sha256(body).hexdigest(), expected):
       raise SystemExit('Bundle hash mismatch; stop')
   print('Bundle byte integrity passed; schema/content validation still required')
   PY
   ```

   Do not follow redirects with an authorization header. The example does not
   follow redirects; any redirect, size limit, timeout or failed HTTP response is
   incomplete retrieval. Stop on a failed download and do not consume a partial
   or previously saved file. Do not print bodies, headers, hashes or private IDs.
4. Only after the byte hash matches, validate JSON/schema and release metadata
   using the owner-provided contract/validator. Pin release
   `20260907-20260927-29aba3d42a411b8a`, September 7–27, 2026 inclusive and
   `America/Los_Angeles`. Reject a wrong release, unsupported schema, wrong date
   window, malformed money or missing provenance. A hash match proves byte
   identity to the trusted handoff, not completeness or metric meaning. No bundle
   schema is implemented by Reports. The source-owned `sales_bundle.py verify`
   CLI was exercised against the actual downloaded bytes with the pinned dates.
   A remote consumer still needs the owner-provided validator/schema instructions
   if that private implementation is unavailable in its runtime.

## Interpret the three weeks

Use the [Sales definition](recipes/sales.md), [pilot](recipes/sales-pilot.md) and
[dashboard SOP](dashboard.md). These are historical data for the complete
Monday–Sunday weeks September 7–13, 14–20 and 21–27, 2026, starting September 7,
14 and 21 in America/Los_Angeles. Show source-as-of and extraction timestamps;
the period is not a claim of current coverage.

The bundle preserves exact integer USD cents **and original pilot integer
strings**, weekly and source/account/location subtotals, normalized source events
and provenance, release/schema/transformation hashes and source timestamps. It
also preserves unknown, partial, refund and classification states, existing
comparison evidence and **two unresolved Sales workbook differences**. Read their
affected cells/metrics, deltas and evidence from the private bundle; do not invent
explanations or publish their business values here. Use exact integer arithmetic;
do not round-trip integer strings through floating point or replace them with
formatted dollars. Use the shared Sales aggregation in
`master_planning/scripts/data_bank_pilot.py`; consume its exported results rather
than creating a second normalizer or aggregation implementation in Reports.

Retain source-scoped account/location identities and local event dates. Workbook
market labels are **not verified Square location identities**. No verified dated
venue mapping is available in this selected export. Location subtotals must remain
location subtotals; physical market/venue totals require separately reviewed dated
mapping evidence. Do not create that mapping from similar labels.

Known subtotals are not necessarily complete totals. Missing data is not zero.
Keep unknown sales, incomplete coverage, unknown classifications and unreconciled
refunds visible. Never add payments to sales, treat comparison evidence as another
sales source, fill gaps from workbook values or force agreement with balancing
adjustments. Keep the two unresolved differences unresolved until new evidence
explains them. Category, cost, goals and profit rows need their own source evidence.

## Remote acceptance and handoff

Follow the [testing guide](testing.md#private-sales-bundle-remote-acceptance).
Require both an authorized download with hash/schema/period validation and denial
to an unauthenticated request and an ungranted Google identity through the actual
interface. Do not revoke the intended reader or broaden sharing to test denial.
Keep dated receipts private, separating local/mocked checks, provisioning and
actual remote checks. Download capability, Sheets access, a successful metadata
read or an empty Drive search is not completed remote acceptance.

The initial file provisioning and private trust handoff are complete. The remaining
remote acceptance step is denial to a valid Google identity without file access.
`master_planning` remains responsible for authoritative validation,
export/schema changes, calculation fixes and new releases. A remote agent still
needs a working authenticated byte download, the validator contract and actual
denial tests. A dashboard additionally needs separate reference-workbook read and
private Sheets creation permissions. This discovery task does not authorize
workbook changes, operational writes, email, scheduling, publication or deployment.
