@peektravel/app-utilities 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/llms.txt ADDED
@@ -0,0 +1,77 @@
1
+ # @peektravel/app-utilities
2
+
3
+ > Dependency-light TypeScript library wrapping the Peek "backoffice" GraphQL
4
+ > gateway. Callers only touch `PeekAccessService`, the per-resource services it
5
+ > hands out, and clean data-model types — never raw GraphQL. Ships dual ESM+CJS
6
+ > with bundled `.d.ts`. Only runtime dependency: `jsonwebtoken`.
7
+
8
+ The authoritative, always-in-sync contract is the bundled type declarations
9
+ (`dist/index.d.ts`) — read them via go-to-definition. This file is a map; the
10
+ `.d.ts` and `README.md` (also shipped) have full detail and examples.
11
+
12
+ ## Entry point
13
+
14
+ Construct one `PeekAccessService` per install, then call `get<Resource>Service()`
15
+ accessors (each memoized, bound to a shared authenticated transport that mints
16
+ and caches a short-lived JWT).
17
+
18
+ ```ts
19
+ import { PeekAccessService } from "@peektravel/app-utilities";
20
+
21
+ const peek = new PeekAccessService({
22
+ installId, // JWT subject
23
+ jwtSecret, // HMAC secret signing the JWT
24
+ issuer, // app name (JWT issuer)
25
+ appId, // gateway path segment
26
+ gatewayKey, // pk-api-key header
27
+ // optional: baseUrl, tokenTtlSeconds, tokenRefreshLeewaySeconds,
28
+ // retryDelaysMs, logger, fetch, itemOptionsPageSize
29
+ });
30
+ ```
31
+
32
+ ## Resources (accessor → methods)
33
+
34
+ - `getProductService()` — `getAllProducts()` (flat list of activities + add-ons;
35
+ add-ons have `type === ADD_ON_PRODUCT_TYPE`)
36
+ - `getAccountUserService()` — `getAll()`, `getById(userId)`
37
+ - `getResourcePoolService()` — `getAll(mode?)`
38
+ - `getTimeslotService()` — `getForDay(productId, date, filter?)`, `getById(id)`,
39
+ `setAvailability(...)`, `setNotes(...)`, `assignGuide({timeslotIds, guideIds, action})`
40
+ - `getResellerService()` — `getAllChannels(agentsPerChannel?)`
41
+ - `getPromoCodeService()` — `getAll()`, `create(input)`
42
+ - `getDailyNoteService()` — `getToday()`, `update(note)`
43
+ - `getAvailabilityService()` — `getAvailabilityTimes({activityId, date, resourceOptionQuantities})`
44
+ - `getMembershipService()` — `getAll()`, `purchase(input)`
45
+ - `getBookingService()` — `getById(id, opts?)`, `searchByTimeRange(input)`,
46
+ `searchByTimeslot(id, opts?)`, `getGuests(id)`, `getPaymentsOnFile(id)`,
47
+ `appendNote(id, note, mode?)`, `setCheckinStatus(id, checkedIn)`, `cancel(id, notes?)`,
48
+ `makePayment(input)`, `refund(input)`, `createInvoiceLink(id)`,
49
+ `listAddons(id)`, `addAddon(id, {addonOptionId, quantity})`,
50
+ `removeAddon(id, {addonOptionId, quantity})`, `create(input)`
51
+
52
+ ## Input conventions (enforced in the service layer; violations throw plain Error)
53
+
54
+ - Booking ids normalized (lowercased, `-`→`_`): `B-ABC123` == `b_abc123`.
55
+ Payment/refund need an id resolving to `b_…`.
56
+ - Quantities: positive-integer strings (`"1"`, `"2"`).
57
+ - Currency: 3-letter uppercase ISO (`"USD"`). Amounts: numeric strings (`"25.00"`).
58
+ - Payment source ids: `ps_…` or `cash/cash` | `custom/other` | `custom/voucher`.
59
+ Payment ids (refunds): `pmt_…`.
60
+ - Idempotency key required on `makePayment`, `refund`, `create({markAsPaid:true})`.
61
+ - `create()` uses pre-resolved ids only (resolve via product + availability
62
+ services); no free-text matching.
63
+
64
+ ## Errors
65
+
66
+ - `AdminAccountRequiredError` (HTTP 418), `RateLimitError` (HTTP 429 after
67
+ retries), `PeekGraphQLError` (`.graphqlErrors` holds the raw array) — all
68
+ importable; branch with `instanceof`.
69
+ - Plain `Error` for validation/precondition failures thrown before any request.
70
+
71
+ ## Notes for consumers
72
+
73
+ - Install is from GitHub Packages (private). Add an `.npmrc` mapping the
74
+ `@peek-travel` scope to `https://npm.pkg.github.com` with a `read:packages`
75
+ token. See README "Install".
76
+ - Everything not re-exported from the package root is internal — do not import
77
+ from subpaths; rely on the public barrel.
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@peektravel/app-utilities",
3
+ "version": "0.1.1",
4
+ "description": "GraphQL JS mapping utilities extracted from the Peek Pro Autopilot connector.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/peek-travel/app-utilities.git"
9
+ },
10
+ "type": "module",
11
+ "main": "./dist/index.cjs",
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "require": {
21
+ "types": "./dist/index.d.cts",
22
+ "default": "./dist/index.cjs"
23
+ }
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "llms.txt"
30
+ ],
31
+ "sideEffects": false,
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup",
37
+ "dev": "tsup --watch",
38
+ "clean": "rm -rf dist coverage",
39
+ "typecheck": "tsc --noEmit",
40
+ "lint": "eslint .",
41
+ "lint:fix": "eslint . --fix",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest",
44
+ "test:coverage": "vitest run --coverage",
45
+ "check:exports": "attw --pack .",
46
+ "check:publint": "publint",
47
+ "prepublishOnly": "npm run build && npm run check:publint && npm run check:exports"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "dependencies": {
53
+ "jsonwebtoken": "^9.0.2"
54
+ },
55
+ "devDependencies": {
56
+ "@arethetypeswrong/cli": "^0.18.2",
57
+ "@eslint/js": "^9.34.0",
58
+ "@types/jsonwebtoken": "^9.0.10",
59
+ "@types/node": "^22.18.0",
60
+ "@vitest/coverage-v8": "^4.1.8",
61
+ "eslint": "^9.34.0",
62
+ "publint": "^0.3.14",
63
+ "tsup": "^8.5.0",
64
+ "typescript": "^5.9.3",
65
+ "typescript-eslint": "^8.40.0",
66
+ "vitest": "^4.1.8"
67
+ }
68
+ }