@pagaqr/mcp 0.0.0-stage → 0.7.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/CHANGELOG.md +15 -0
- package/LICENSE +202 -0
- package/NOTICE +9 -0
- package/README.md +99 -2
- package/dist/capture-cli.d.ts +2 -0
- package/dist/capture-cli.js +34 -0
- package/dist/capture-local.d.ts +9 -0
- package/dist/capture-local.js +18 -0
- package/dist/capture-store.d.ts +7 -0
- package/dist/capture-store.js +175 -0
- package/dist/catalogue.d.ts +33 -0
- package/dist/catalogue.js +78 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +27 -0
- package/dist/diagnose.d.ts +23 -0
- package/dist/diagnose.js +93 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +134 -0
- package/dist/invocation-log.d.ts +9 -0
- package/dist/invocation-log.js +70 -0
- package/dist/masked-terminal.d.ts +4 -0
- package/dist/masked-terminal.js +71 -0
- package/dist/next-postgres.json +99 -0
- package/dist/sbom.cdx.json +523 -0
- package/dist/setup/database.d.ts +7 -0
- package/dist/setup/database.js +83 -0
- package/dist/setup/notice.d.ts +2 -0
- package/dist/setup/notice.js +2 -0
- package/dist/setup/run.d.ts +25 -0
- package/dist/setup/run.js +215 -0
- package/dist/setup/runtime.js +837 -0
- package/dist/setup/state.d.ts +7 -0
- package/dist/setup/state.js +81 -0
- package/dist/setup/step.d.ts +59 -0
- package/dist/setup/step.js +9 -0
- package/dist/setup/steps/pey.d.ts +8 -0
- package/dist/setup/steps/pey.js +271 -0
- package/dist/setup/steps/vercel.d.ts +5 -0
- package/dist/setup/steps/vercel.js +375 -0
- package/dist/setup/store-secrets.d.ts +3 -0
- package/dist/setup/store-secrets.js +67 -0
- package/dist/setup/terminal-guard.d.ts +9 -0
- package/dist/setup/terminal-guard.js +17 -0
- package/dist/setup/verify.d.ts +34 -0
- package/dist/setup/verify.js +144 -0
- package/dist/setup-cli.d.ts +2 -0
- package/dist/setup-cli.js +70 -0
- package/dist/template.d.ts +4 -0
- package/dist/template.js +119 -0
- package/dist/webhook.d.ts +1 -0
- package/dist/webhook.js +30 -0
- package/package.json +51 -3
|
@@ -0,0 +1,837 @@
|
|
|
1
|
+
import pg, { escapeIdentifier } from "pg";
|
|
2
|
+
import { writeFileSync } from "node:fs";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { parse } from "parse5";
|
|
7
|
+
// ../postgres/src/client.ts
|
|
8
|
+
/**
|
|
9
|
+
* Takes a client from the pool for one unit of work. A connection lost while checked out is
|
|
10
|
+
* reported on the client as well as on the failed query: the query's rejection carries it, and
|
|
11
|
+
* without this listener the event would crash the process.
|
|
12
|
+
*/
|
|
13
|
+
async function checkout(pool) {
|
|
14
|
+
const client = await pool.connect();
|
|
15
|
+
const ignore = () => void 0;
|
|
16
|
+
client.on("error", ignore);
|
|
17
|
+
return {
|
|
18
|
+
client,
|
|
19
|
+
done: (broken = false) => {
|
|
20
|
+
client.off("error", ignore);
|
|
21
|
+
client.release(broken);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// ../postgres/src/migrations.ts
|
|
26
|
+
const MIGRATIONS = [
|
|
27
|
+
{
|
|
28
|
+
name: "001_initial.sql",
|
|
29
|
+
sql: "-- The guarantees live in the database: a second confirmation, a replayed notice or a second\n-- active attempt is rejected by a constraint, not by the application remembering to check.\n\nCREATE TABLE pagaqr_attempts (\n attempt_id text PRIMARY KEY,\n order_id text NOT NULL,\n order_version integer NOT NULL CHECK (order_version >= 1),\n amount bigint NOT NULL CHECK (amount > 0),\n channel text NOT NULL CHECK (channel IN ('qr', 'push')),\n state text NOT NULL CHECK (state IN ('pending', 'charge_issued', 'charge_uncertain', 'paid', 'fulfillment_queued', 'expired')),\n charge_id text UNIQUE,\n expires_at timestamptz NOT NULL,\n cancelled boolean NOT NULL DEFAULT false,\n created_at timestamptz NOT NULL DEFAULT now()\n);\n\n-- One attempt in flight per order: a second one waits until the first resolves or expires.\nCREATE UNIQUE INDEX pagaqr_attempts_one_active\n ON pagaqr_attempts (order_id)\n WHERE state IN ('pending', 'charge_issued', 'charge_uncertain') AND NOT cancelled;\n\n-- A notice is applied once: its id is the key.\nCREATE TABLE pagaqr_events (\n event_id text PRIMARY KEY,\n received_at timestamptz NOT NULL\n);\n\n-- One confirmation per order, and a transaction confirms at most one order.\nCREATE TABLE pagaqr_confirmations (\n order_id text PRIMARY KEY,\n attempt_id text NOT NULL REFERENCES pagaqr_attempts (attempt_id),\n transaction_id text NOT NULL UNIQUE,\n amount bigint NOT NULL CHECK (amount > 0),\n confirmed_at timestamptz NOT NULL\n);\n\n-- An incident never confirms nor fulfils an order; it is kept for the owner to review.\nCREATE TABLE pagaqr_incidents (\n incident_id bigserial PRIMARY KEY,\n attempt_id text,\n transaction_id text,\n reason text NOT NULL,\n recorded_at timestamptz NOT NULL\n);\n"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "002_lifecycle.sql",
|
|
33
|
+
sql: "-- The rest of the attempt lifecycle, the push limit and the fulfillment outbox.\n\nALTER TABLE pagaqr_attempts DROP CONSTRAINT pagaqr_attempts_state_check;\nALTER TABLE pagaqr_attempts ADD CONSTRAINT pagaqr_attempts_state_check\n CHECK (state IN ('pending', 'charge_issued', 'charge_uncertain', 'paid', 'fulfillment_queued', 'expired', 'cancelled'));\n\n-- The phone is never stored: only a keyed hash of it, enough to count sends.\nALTER TABLE pagaqr_attempts ADD COLUMN phone_key text;\n\n-- Push sends per phone key and fixed window, counted inside the transaction that reserves.\nCREATE TABLE pagaqr_push_counters (\n phone_key text NOT NULL,\n window_start timestamptz NOT NULL,\n sends integer NOT NULL CHECK (sends > 0),\n PRIMARY KEY (phone_key, window_start)\n);\n\n-- The order to deliver, written in the same transaction as the confirmation; handed out once.\nCREATE TABLE pagaqr_fulfillments (\n order_id text PRIMARY KEY REFERENCES pagaqr_confirmations (order_id),\n transaction_id text NOT NULL UNIQUE,\n amount bigint NOT NULL CHECK (amount > 0),\n created_at timestamptz NOT NULL,\n taken_at timestamptz\n);\n\n-- The history is insert-only for everyone but the owner of the tables.\nREVOKE UPDATE, DELETE, TRUNCATE ON pagaqr_events, pagaqr_incidents, pagaqr_confirmations FROM PUBLIC;\n"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "003_store_limit.sql",
|
|
37
|
+
sql: "-- Charges the whole store starts per fixed window, counted inside the transaction that reserves.\n\nCREATE TABLE pagaqr_store_counters (\n window_start timestamptz PRIMARY KEY,\n charges integer NOT NULL CHECK (charges > 0)\n);\n"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "004_fulfillment_lease.sql",
|
|
41
|
+
sql: "-- An order to fulfil is lent to its consumer for a while and closed by an acknowledgement: if the\n-- consumer stops before acknowledging, the order is handed out again when its lease runs out.\n\nALTER TABLE pagaqr_fulfillments ADD COLUMN lease_until timestamptz;\nALTER TABLE pagaqr_fulfillments ADD COLUMN acknowledged_at timestamptz;\n"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "005_sliding_limits.sql",
|
|
45
|
+
sql: "-- The send limits count the attempts themselves over a sliding window: a fixed window aligned to\n-- the clock let a fourth push through within ten minutes when the sends straddled its edge. The\n-- counters it kept are no longer read.\n\nCREATE INDEX pagaqr_attempts_phone_created ON pagaqr_attempts (phone_key, created_at)\n WHERE phone_key IS NOT NULL;\nCREATE INDEX pagaqr_attempts_created ON pagaqr_attempts (created_at);\n\nDROP TABLE pagaqr_push_counters;\nDROP TABLE pagaqr_store_counters;\n"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "006_shared_route_stores.sql",
|
|
49
|
+
sql: "-- What the Fetch routes keep between requests, shared by every instance of the store: the QR of\n-- an order until it expires, and the phones seen in a session during the last hour. Sessions and\n-- phones are stored only as keyed hashes.\n\nCREATE TABLE pagaqr_qr_material (\n order_id text PRIMARY KEY,\n charge_id text NOT NULL,\n payload text NOT NULL,\n image text,\n expires_at timestamptz NOT NULL\n);\n\nCREATE TABLE pagaqr_session_phones (\n session_key text NOT NULL,\n phone_key text NOT NULL,\n observed_at timestamptz NOT NULL,\n PRIMARY KEY (session_key, phone_key)\n);\n"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "007_incident_worklist.sql",
|
|
53
|
+
sql: "-- The incidents become the store's work list: each one is resolved by writing its resolution, so\n-- the incident history itself stays insert-only. A transaction is at most one incident, whichever\n-- path saw it first, so the same money is never refunded twice. The phones of the route sessions\n-- are pruned by age, whatever the session.\n\nCREATE TABLE pagaqr_incident_resolutions (\n incident_id bigint PRIMARY KEY REFERENCES pagaqr_incidents (incident_id),\n resolved_at timestamptz NOT NULL\n);\n\nCREATE UNIQUE INDEX pagaqr_incidents_one_per_transaction ON pagaqr_incidents (transaction_id)\n WHERE transaction_id IS NOT NULL;\n\nCREATE INDEX pagaqr_session_phones_observed ON pagaqr_session_phones (observed_at);\n"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "008_order_timeline.sql",
|
|
57
|
+
sql: "-- A trace of committed order transitions, with only the fields the buyer or operator needs.\nCREATE TABLE pagaqr_order_timeline (\n entry_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,\n order_id text NOT NULL,\n occurred_at timestamptz NOT NULL DEFAULT clock_timestamp(),\n kind text NOT NULL CHECK (kind IN (\n 'attempt_reserved', 'charge_issued', 'charge_uncertain', 'charge_failed',\n 'attempt_cancelled', 'attempt_expired', 'payment_confirmed', 'incident_recorded',\n 'fulfillment_queued', 'fulfillment_acknowledged', 'incident_resolved'\n )),\n channel text CHECK (channel IN ('qr', 'push')),\n amount bigint CHECK (amount > 0 AND amount <= 9007199254740991),\n order_version integer CHECK (order_version >= 1),\n reason text,\n CHECK ((kind = 'attempt_reserved') = (channel IS NOT NULL)),\n CHECK ((kind = 'attempt_reserved') = (order_version IS NOT NULL)),\n CHECK ((kind IN ('attempt_reserved', 'payment_confirmed')) = (amount IS NOT NULL)),\n CHECK ((kind IN ('attempt_cancelled', 'incident_recorded', 'incident_resolved')) = (reason IS NOT NULL)),\n CHECK (CASE\n WHEN kind = 'attempt_cancelled' THEN reason IN ('order_changed', 'order_cancelled')\n WHEN kind IN ('incident_recorded', 'incident_resolved') THEN reason IN (\n 'amount_short', 'amount_excess', 'unexpected_fee_or_tip', 'inconsistent_breakdown',\n 'notice_and_query_mismatch', 'duplicate_payment', 'late_payment', 'unknown_attempt',\n 'account_mismatch', 'unexpected_transaction_kind', 'stale_order_version',\n 'inexact_amount', 'breakdown_missing', 'invalid_order_total'\n )\n ELSE reason IS NULL\n END)\n);\n\nCREATE INDEX pagaqr_order_timeline_insertion ON pagaqr_order_timeline (order_id, entry_id);\nREVOKE UPDATE, DELETE, TRUNCATE ON pagaqr_order_timeline FROM PUBLIC;\n"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "009_notice_receipts.sql",
|
|
61
|
+
sql: "-- Keep the original authenticated receipt independently of the record that applies its settlement.\nCREATE TABLE pagaqr_notice_receipts (\n event_id text PRIMARY KEY,\n received_at timestamptz NOT NULL,\n body_sha256 text NOT NULL CHECK (body_sha256 ~ '^[0-9a-f]{64}$'),\n transaction_id text,\n charge_id text\n);\n\nCREATE INDEX pagaqr_notice_receipts_by_charge ON pagaqr_notice_receipts (charge_id);\nCREATE INDEX pagaqr_notice_receipts_by_transaction ON pagaqr_notice_receipts (transaction_id);\nCREATE INDEX pagaqr_confirmations_recent ON pagaqr_confirmations (confirmed_at DESC, order_id);\n\nREVOKE UPDATE, DELETE, TRUNCATE ON pagaqr_notice_receipts FROM PUBLIC;\n"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "010_link_notice_evidence.sql",
|
|
65
|
+
sql: "-- A historic event can exist without evidence of the bytes it applied.\nALTER TABLE pagaqr_events\n ADD COLUMN receipt_sha256 text CHECK (receipt_sha256 ~ '^[0-9a-f]{64}$');\n"
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
// ../postgres/src/migrate.ts
|
|
69
|
+
const LOCK_KEY = 4718201;
|
|
70
|
+
/**
|
|
71
|
+
* Applies, in order and once each, the migrations of `migrations/`, carried in the package's code so no bundler or
|
|
72
|
+
* serverless host has to ship the folder. Each one runs in its own transaction, and an advisory lock keeps two
|
|
73
|
+
* instances from migrating the same database at once.
|
|
74
|
+
*/
|
|
75
|
+
async function migrate(pool) {
|
|
76
|
+
const { client, done } = await checkout(pool);
|
|
77
|
+
try {
|
|
78
|
+
await client.query("SELECT pg_advisory_lock($1)", [LOCK_KEY]);
|
|
79
|
+
await client.query("CREATE TABLE IF NOT EXISTS pagaqr_migrations (name text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())");
|
|
80
|
+
const previous = await client.query("SELECT name FROM pagaqr_migrations");
|
|
81
|
+
const applied = new Set(previous.rows.map((row) => row.name));
|
|
82
|
+
for (const { name, sql } of MIGRATIONS) {
|
|
83
|
+
if (applied.has(name)) continue;
|
|
84
|
+
await client.query("BEGIN");
|
|
85
|
+
try {
|
|
86
|
+
await client.query(sql);
|
|
87
|
+
await client.query("INSERT INTO pagaqr_migrations (name) VALUES ($1)", [name]);
|
|
88
|
+
await client.query("COMMIT");
|
|
89
|
+
} catch (error) {
|
|
90
|
+
await client.query("ROLLBACK").catch(() => void 0);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} finally {
|
|
95
|
+
done(!await client.query("SELECT pg_advisory_unlock($1)", [LOCK_KEY]).then(() => true, () => false));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// ../postgres/src/roles.ts
|
|
99
|
+
const ROLE = /^[a-z_][a-z0-9_]{0,62}$/;
|
|
100
|
+
const RESERVED = /* @__PURE__ */ new Set([
|
|
101
|
+
"public",
|
|
102
|
+
"current_user",
|
|
103
|
+
"session_user",
|
|
104
|
+
"current_role",
|
|
105
|
+
"user",
|
|
106
|
+
"none",
|
|
107
|
+
"neon_superuser"
|
|
108
|
+
]);
|
|
109
|
+
function assertApplicationRoleName(role) {
|
|
110
|
+
if (!ROLE.test(role) || role.startsWith("pg_") || RESERVED.has(role)) throw new Error("The application role must be a plain lowercase name of its own");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Grants the role the application connects with exactly what pagaqr needs. The history — notices,
|
|
114
|
+
* incidents and confirmations — is insert-only for it, and it may update only the columns the
|
|
115
|
+
* lifecycle moves: never an amount, an order or a transaction. The migrations run with the owner
|
|
116
|
+
* of the tables; the application never should.
|
|
117
|
+
*/
|
|
118
|
+
async function grantApplicationRole(pool, role) {
|
|
119
|
+
assertApplicationRoleName(role);
|
|
120
|
+
const { client, done } = await checkout(pool);
|
|
121
|
+
const to = client.escapeIdentifier(role);
|
|
122
|
+
try {
|
|
123
|
+
await client.query("BEGIN");
|
|
124
|
+
await client.query(`GRANT SELECT, INSERT ON pagaqr_attempts, pagaqr_fulfillments TO ${to}`);
|
|
125
|
+
await client.query(`GRANT UPDATE (state, charge_id, cancelled) ON pagaqr_attempts TO ${to}`);
|
|
126
|
+
await client.query(`GRANT UPDATE (taken_at, lease_until, acknowledged_at) ON pagaqr_fulfillments TO ${to}`);
|
|
127
|
+
await client.query(`GRANT SELECT, INSERT ON pagaqr_events, pagaqr_incidents, pagaqr_confirmations TO ${to}`);
|
|
128
|
+
await client.query(`GRANT SELECT, INSERT, UPDATE, DELETE ON pagaqr_qr_material, pagaqr_session_phones TO ${to}`);
|
|
129
|
+
await client.query(`GRANT SELECT, INSERT ON pagaqr_incident_resolutions TO ${to}`);
|
|
130
|
+
await client.query(`GRANT SELECT, INSERT ON pagaqr_order_timeline, pagaqr_notice_receipts TO ${to}`);
|
|
131
|
+
await client.query(`GRANT SELECT ON pagaqr_migrations TO ${to}`);
|
|
132
|
+
await client.query(`GRANT USAGE, SELECT ON SEQUENCE pagaqr_incidents_incident_id_seq TO ${to}`);
|
|
133
|
+
await client.query("COMMIT");
|
|
134
|
+
} catch (error) {
|
|
135
|
+
done(!await client.query("ROLLBACK").then(() => true, () => false));
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
done();
|
|
139
|
+
}
|
|
140
|
+
// ../../apps/demo/src/store/database-role.ts
|
|
141
|
+
var StoreDatabaseNotReady = class extends Error {
|
|
142
|
+
code;
|
|
143
|
+
constructor(code) {
|
|
144
|
+
super(code);
|
|
145
|
+
this.code = code;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
async function assertApplicationDatabase(pool) {
|
|
149
|
+
const status = (await pool.query(`
|
|
150
|
+
WITH required(name) AS (
|
|
151
|
+
VALUES ('store_orders'), ('pagaqr_migrations'), ('pagaqr_attempts'),
|
|
152
|
+
('pagaqr_confirmations'), ('pagaqr_events'), ('pagaqr_incidents'), ('pagaqr_fulfillments'),
|
|
153
|
+
('pagaqr_qr_material'), ('pagaqr_session_phones'), ('pagaqr_incident_resolutions'),
|
|
154
|
+
('pagaqr_order_timeline'), ('pagaqr_notice_receipts'), ('store_privacy_notices'), ('store_privacy_consents'), ('store_order_support')
|
|
155
|
+
), relations AS (
|
|
156
|
+
SELECT c.oid, c.relname, c.relowner,
|
|
157
|
+
CASE c.relname
|
|
158
|
+
WHEN 'pagaqr_attempts' THEN ARRAY['state', 'charge_id', 'cancelled']
|
|
159
|
+
WHEN 'pagaqr_fulfillments' THEN ARRAY['taken_at', 'lease_until', 'acknowledged_at']
|
|
160
|
+
WHEN 'store_orders' THEN ARRAY['version', 'lines', 'total_centavos', 'cancelled', 'fulfilled_at']
|
|
161
|
+
ELSE ARRAY[]::text[]
|
|
162
|
+
END AS writable_columns,
|
|
163
|
+
c.relname IN ('pagaqr_qr_material', 'pagaqr_session_phones') AS is_cache
|
|
164
|
+
FROM required AS r JOIN pg_class AS c ON c.oid = to_regclass(r.name)
|
|
165
|
+
)
|
|
166
|
+
SELECT
|
|
167
|
+
(SELECT count(*) FROM relations WHERE has_table_privilege(oid, 'SELECT'))
|
|
168
|
+
= (SELECT count(*) FROM required) AND EXISTS (
|
|
169
|
+
SELECT 1 FROM relations r JOIN pg_attribute col ON col.attrelid = r.oid
|
|
170
|
+
WHERE r.relname = 'pagaqr_events' AND col.attname = 'receipt_sha256'
|
|
171
|
+
AND col.attnum > 0 AND NOT col.attisdropped
|
|
172
|
+
) AS prepared,
|
|
173
|
+
NOT (
|
|
174
|
+
has_database_privilege(current_database(), 'CREATE') OR
|
|
175
|
+
has_schema_privilege(current_schema(), 'CREATE') OR
|
|
176
|
+
EXISTS (SELECT 1 FROM unnest(ARRAY['store_privacy_blocks', 'store_evidence_read_audit', 'store_privacy_use_stops', 'store_privacy_corrections', 'store_security_reviews', 'store_security_followups', 'store_privacy_requests', 'store_refund_reviews', 'store_payment_ledger_refs', 'store_consumer_claims', 'store_contract_defaults', 'store_privacy_cancellation_terms', 'store_privacy_cancellation_reviews']) AS private(name)
|
|
177
|
+
WHERE has_table_privilege(to_regclass(private.name), 'SELECT,INSERT,UPDATE,DELETE,TRUNCATE')
|
|
178
|
+
OR has_any_column_privilege(to_regclass(private.name), 'SELECT,INSERT,UPDATE,REFERENCES')) OR
|
|
179
|
+
EXISTS (SELECT 1 FROM unnest(ARRAY['public.store_request_refund(uuid,text,timestamptz,bigint)', 'public.store_approve_refund(uuid,timestamptz)', 'public.store_record_refund_result(uuid,timestamptz,text,uuid)',
|
|
180
|
+
'public.store_open_consumer_claim(uuid,text,text,text,uuid,uuid,timestamptz)', 'public.store_decide_consumer_claim(uuid,timestamptz,text,bigint)',
|
|
181
|
+
'public.store_resolve_consumer_claim(uuid,timestamptz,uuid)']) AS private(signature)
|
|
182
|
+
WHERE has_function_privilege(to_regprocedure(private.signature), 'EXECUTE')) OR
|
|
183
|
+
EXISTS (
|
|
184
|
+
SELECT 1 FROM pg_roles WHERE pg_has_role(oid, 'MEMBER') AND (
|
|
185
|
+
rolsuper OR rolcreaterole OR rolcreatedb OR rolbypassrls OR rolreplication OR
|
|
186
|
+
rolname = 'neon_superuser'
|
|
187
|
+
)
|
|
188
|
+
) OR EXISTS (SELECT 1 FROM relations WHERE pg_has_role(relowner, 'MEMBER')) OR
|
|
189
|
+
EXISTS (
|
|
190
|
+
SELECT 1 FROM relations WHERE has_table_privilege(oid, 'TRUNCATE')
|
|
191
|
+
OR (NOT is_cache AND has_table_privilege(oid, 'DELETE'))
|
|
192
|
+
) OR EXISTS (
|
|
193
|
+
SELECT 1 FROM relations r JOIN pg_attribute col ON col.attrelid = r.oid
|
|
194
|
+
WHERE col.attnum > 0 AND NOT col.attisdropped
|
|
195
|
+
AND NOT r.is_cache
|
|
196
|
+
AND col.attname::text <> ALL (r.writable_columns)
|
|
197
|
+
AND has_column_privilege(r.oid, col.attnum, 'UPDATE')
|
|
198
|
+
)
|
|
199
|
+
) AS restricted,
|
|
200
|
+
NOT EXISTS (
|
|
201
|
+
SELECT 1 FROM relations
|
|
202
|
+
WHERE (relname <> 'pagaqr_migrations' AND NOT has_table_privilege(oid, 'INSERT'))
|
|
203
|
+
OR (is_cache AND (NOT has_table_privilege(oid, 'UPDATE') OR NOT has_table_privilege(oid, 'DELETE')))
|
|
204
|
+
) AND NOT EXISTS (
|
|
205
|
+
SELECT 1 FROM relations r, unnest(r.writable_columns) AS required_column(name)
|
|
206
|
+
WHERE NOT EXISTS (
|
|
207
|
+
SELECT 1 FROM pg_attribute col
|
|
208
|
+
WHERE col.attrelid = r.oid AND col.attname = required_column.name
|
|
209
|
+
AND col.attnum > 0 AND NOT col.attisdropped
|
|
210
|
+
AND has_column_privilege(r.oid, col.attnum, 'UPDATE')
|
|
211
|
+
)
|
|
212
|
+
) AND COALESCE(
|
|
213
|
+
has_sequence_privilege(to_regclass('pagaqr_incidents_incident_id_seq'), 'USAGE'), false
|
|
214
|
+
) AS operable
|
|
215
|
+
`)).rows[0];
|
|
216
|
+
if (!status?.prepared) throw new StoreDatabaseNotReady("database_schema_unprepared");
|
|
217
|
+
if (!status.restricted) throw new StoreDatabaseNotReady("database_role_overprivileged");
|
|
218
|
+
if (!status.operable) throw new StoreDatabaseNotReady("database_schema_unprepared");
|
|
219
|
+
}
|
|
220
|
+
// ../../apps/demo/src/store/store-schema.ts
|
|
221
|
+
const SCHEMA = `
|
|
222
|
+
CREATE TABLE IF NOT EXISTS store_orders (
|
|
223
|
+
order_id text PRIMARY KEY,
|
|
224
|
+
version integer NOT NULL CHECK (version >= 1),
|
|
225
|
+
lines jsonb NOT NULL,
|
|
226
|
+
total_centavos bigint NOT NULL CHECK (total_centavos > 0),
|
|
227
|
+
cancelled boolean NOT NULL DEFAULT false,
|
|
228
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
229
|
+
);
|
|
230
|
+
-- The SHA-256 of the buyer session that created the order; never the session itself.
|
|
231
|
+
ALTER TABLE store_orders ADD COLUMN IF NOT EXISTS buyer_session_hash text;
|
|
232
|
+
-- When the store delivered the paid order; written once.
|
|
233
|
+
ALTER TABLE store_orders ADD COLUMN IF NOT EXISTS fulfilled_at timestamptz;
|
|
234
|
+
-- The immutable terms acceptance of the order at its initial version.
|
|
235
|
+
ALTER TABLE store_orders ADD COLUMN IF NOT EXISTS acceptance jsonb;
|
|
236
|
+
-- When the store first made each privacy notice available for the order.
|
|
237
|
+
CREATE TABLE IF NOT EXISTS store_privacy_notices (
|
|
238
|
+
order_id text NOT NULL REFERENCES store_orders(order_id),
|
|
239
|
+
notice_version text NOT NULL,
|
|
240
|
+
available_at timestamptz NOT NULL,
|
|
241
|
+
PRIMARY KEY (order_id, notice_version)
|
|
242
|
+
);
|
|
243
|
+
REVOKE UPDATE, DELETE, TRUNCATE ON store_privacy_notices FROM PUBLIC;
|
|
244
|
+
-- Privacy case files belong to the operator, with no grants for the store application.
|
|
245
|
+
CREATE TABLE IF NOT EXISTS store_privacy_blocks (
|
|
246
|
+
order_id text PRIMARY KEY REFERENCES store_orders(order_id),
|
|
247
|
+
buyer_session_hash text CHECK (buyer_session_hash ~ '^[a-f0-9]{64}$'),
|
|
248
|
+
case_id uuid NOT NULL UNIQUE,
|
|
249
|
+
blocked_at timestamptz NOT NULL,
|
|
250
|
+
blocked_until timestamptz NOT NULL CHECK (blocked_until > blocked_at),
|
|
251
|
+
retention_basis text NOT NULL DEFAULT 'liability' CHECK (retention_basis IN ('liability', 'legal', 'contract')),
|
|
252
|
+
release_case_id uuid UNIQUE,
|
|
253
|
+
released_at timestamptz,
|
|
254
|
+
released_by name,
|
|
255
|
+
operator_role name NOT NULL DEFAULT current_user,
|
|
256
|
+
purged_at timestamptz,
|
|
257
|
+
CHECK ((purged_at IS NULL) = (buyer_session_hash IS NOT NULL)),
|
|
258
|
+
CHECK (purged_at IS NULL OR purged_at >= blocked_until),
|
|
259
|
+
CHECK ((released_at IS NULL) = (release_case_id IS NULL) AND (released_at IS NULL) = (released_by IS NULL)),
|
|
260
|
+
CHECK (released_at IS NULL OR (released_at >= blocked_until AND retention_basis <> 'liability'))
|
|
261
|
+
);
|
|
262
|
+
DO $privacy$
|
|
263
|
+
BEGIN
|
|
264
|
+
IF NOT EXISTS (
|
|
265
|
+
SELECT 1 FROM pg_constraint
|
|
266
|
+
WHERE conrelid = 'store_privacy_blocks'::regclass
|
|
267
|
+
AND conname = 'store_privacy_blocks_purge_after_release'
|
|
268
|
+
) THEN
|
|
269
|
+
ALTER TABLE store_privacy_blocks ADD CONSTRAINT store_privacy_blocks_purge_after_release
|
|
270
|
+
CHECK (purged_at IS NULL OR retention_basis = 'liability' OR
|
|
271
|
+
(released_at IS NOT NULL AND purged_at >= released_at));
|
|
272
|
+
END IF;
|
|
273
|
+
END;
|
|
274
|
+
$privacy$;
|
|
275
|
+
CREATE INDEX IF NOT EXISTS store_privacy_blocks_due
|
|
276
|
+
ON store_privacy_blocks (blocked_until, order_id) WHERE buyer_session_hash IS NOT NULL;
|
|
277
|
+
REVOKE ALL ON store_privacy_blocks FROM PUBLIC;
|
|
278
|
+
-- Each version of the notice and the order has its own affirmative record.
|
|
279
|
+
CREATE TABLE IF NOT EXISTS store_privacy_consents (
|
|
280
|
+
order_id text NOT NULL,
|
|
281
|
+
order_version integer NOT NULL CHECK (order_version >= 1),
|
|
282
|
+
notice_version text NOT NULL,
|
|
283
|
+
purpose text NOT NULL CHECK (purpose = 'send_order_charge'),
|
|
284
|
+
consented_at timestamptz NOT NULL,
|
|
285
|
+
PRIMARY KEY (order_id, order_version, notice_version, purpose),
|
|
286
|
+
FOREIGN KEY (order_id, notice_version) REFERENCES store_privacy_notices(order_id, notice_version)
|
|
287
|
+
);
|
|
288
|
+
REVOKE UPDATE, DELETE, TRUNCATE ON store_privacy_consents FROM PUBLIC;
|
|
289
|
+
CREATE TABLE IF NOT EXISTS store_evidence_read_audit (
|
|
290
|
+
operator_role name NOT NULL DEFAULT current_user,
|
|
291
|
+
occurred_at timestamptz NOT NULL DEFAULT now(),
|
|
292
|
+
operation text NOT NULL DEFAULT 'export_order_evidence' CHECK (operation = 'export_order_evidence')
|
|
293
|
+
);
|
|
294
|
+
REVOKE ALL ON store_evidence_read_audit FROM PUBLIC;
|
|
295
|
+
-- The timestamp is checked by the phone route while holding the order row.
|
|
296
|
+
ALTER TABLE store_orders ADD COLUMN IF NOT EXISTS phone_use_ended_at timestamptz;
|
|
297
|
+
CREATE TABLE IF NOT EXISTS store_privacy_use_stops (
|
|
298
|
+
order_id text PRIMARY KEY REFERENCES store_orders(order_id),
|
|
299
|
+
case_id uuid NOT NULL UNIQUE,
|
|
300
|
+
stopped_at timestamptz NOT NULL,
|
|
301
|
+
reason text NOT NULL CHECK (reason IN ('revocation', 'opposition')),
|
|
302
|
+
operator_role name NOT NULL DEFAULT current_user
|
|
303
|
+
);
|
|
304
|
+
REVOKE ALL ON store_privacy_use_stops FROM PUBLIC;
|
|
305
|
+
CREATE TABLE IF NOT EXISTS store_privacy_corrections (
|
|
306
|
+
case_id uuid PRIMARY KEY,
|
|
307
|
+
order_id text NOT NULL REFERENCES store_orders(order_id),
|
|
308
|
+
corrected_at timestamptz NOT NULL,
|
|
309
|
+
operator_role name NOT NULL DEFAULT current_user
|
|
310
|
+
);
|
|
311
|
+
REVOKE ALL ON store_privacy_corrections FROM PUBLIC;
|
|
312
|
+
CREATE TABLE IF NOT EXISTS store_security_reviews (
|
|
313
|
+
case_id uuid PRIMARY KEY,
|
|
314
|
+
signal text NOT NULL,
|
|
315
|
+
status text NOT NULL CHECK (status IN ('open', 'review')),
|
|
316
|
+
reason text NOT NULL,
|
|
317
|
+
assigned_queue text,
|
|
318
|
+
reviewed_at timestamptz NOT NULL,
|
|
319
|
+
impact_scope text,
|
|
320
|
+
buyer_advice text,
|
|
321
|
+
operator_role name NOT NULL DEFAULT current_user,
|
|
322
|
+
CHECK ((status = 'open') = (assigned_queue IS NOT NULL))
|
|
323
|
+
);
|
|
324
|
+
REVOKE ALL ON store_security_reviews FROM PUBLIC;
|
|
325
|
+
CREATE TABLE IF NOT EXISTS store_security_followups (
|
|
326
|
+
case_id uuid PRIMARY KEY REFERENCES store_security_reviews(case_id),
|
|
327
|
+
corrective_action text NOT NULL,
|
|
328
|
+
verification text NOT NULL,
|
|
329
|
+
verified_at timestamptz NOT NULL,
|
|
330
|
+
operator_role name NOT NULL DEFAULT current_user
|
|
331
|
+
);
|
|
332
|
+
REVOKE ALL ON store_security_followups FROM PUBLIC;
|
|
333
|
+
CREATE TABLE IF NOT EXISTS store_privacy_requests (
|
|
334
|
+
case_id uuid PRIMARY KEY,
|
|
335
|
+
order_id text NOT NULL REFERENCES store_orders(order_id),
|
|
336
|
+
right_kind text NOT NULL CHECK (right_kind IN ('access', 'rectification', 'cancellation', 'opposition', 'revocation')),
|
|
337
|
+
received_at timestamptz NOT NULL,
|
|
338
|
+
respond_by timestamptz NOT NULL CHECK (respond_by > received_at),
|
|
339
|
+
decision text,
|
|
340
|
+
reason text,
|
|
341
|
+
decided_at timestamptz,
|
|
342
|
+
communicated_at timestamptz,
|
|
343
|
+
communication_ref uuid,
|
|
344
|
+
operator_role name NOT NULL DEFAULT current_user,
|
|
345
|
+
CHECK ((decision IS NULL) = (reason IS NULL) AND (decision IS NULL) = (decided_at IS NULL)
|
|
346
|
+
AND (decision IS NULL) = (communicated_at IS NULL) AND (decision IS NULL) = (communication_ref IS NULL)),
|
|
347
|
+
CHECK (decided_at IS NULL OR (decided_at >= received_at AND communicated_at >= decided_at))
|
|
348
|
+
);
|
|
349
|
+
REVOKE ALL ON store_privacy_requests FROM PUBLIC;
|
|
350
|
+
CREATE TABLE IF NOT EXISTS store_order_support (
|
|
351
|
+
order_id text PRIMARY KEY REFERENCES store_orders(order_id),
|
|
352
|
+
requested_at timestamptz NOT NULL
|
|
353
|
+
);
|
|
354
|
+
REVOKE UPDATE, DELETE, TRUNCATE ON store_order_support FROM PUBLIC;
|
|
355
|
+
CREATE TABLE IF NOT EXISTS store_refund_reviews (
|
|
356
|
+
case_id uuid PRIMARY KEY,
|
|
357
|
+
order_id text NOT NULL UNIQUE REFERENCES store_orders(order_id),
|
|
358
|
+
amount bigint NOT NULL CHECK (amount > 0),
|
|
359
|
+
requested_by name NOT NULL,
|
|
360
|
+
requested_at timestamptz NOT NULL,
|
|
361
|
+
approved_by name,
|
|
362
|
+
approved_at timestamptz,
|
|
363
|
+
resolved_by name,
|
|
364
|
+
resolved_at timestamptz,
|
|
365
|
+
outcome text CHECK (outcome IN ('returned', 'declined')),
|
|
366
|
+
receipt_ref uuid UNIQUE,
|
|
367
|
+
CHECK ((approved_by IS NULL) = (approved_at IS NULL) AND (approved_at IS NULL OR approved_at >= requested_at)),
|
|
368
|
+
CHECK ((resolved_by IS NULL) = (resolved_at IS NULL) AND (resolved_at IS NULL) = (outcome IS NULL)
|
|
369
|
+
AND (outcome IS NULL) = (receipt_ref IS NULL)),
|
|
370
|
+
CHECK (resolved_at IS NULL OR (approved_at IS NOT NULL AND resolved_at >= approved_at))
|
|
371
|
+
);
|
|
372
|
+
REVOKE ALL ON store_refund_reviews FROM PUBLIC;
|
|
373
|
+
CREATE TABLE IF NOT EXISTS store_payment_ledger_refs (
|
|
374
|
+
order_id text PRIMARY KEY REFERENCES store_orders(order_id),
|
|
375
|
+
account_ref uuid NOT NULL,
|
|
376
|
+
sale_receipt_ref uuid NOT NULL UNIQUE,
|
|
377
|
+
recorded_by name NOT NULL DEFAULT session_user,
|
|
378
|
+
recorded_at timestamptz NOT NULL DEFAULT now()
|
|
379
|
+
);
|
|
380
|
+
REVOKE ALL ON store_payment_ledger_refs FROM PUBLIC;
|
|
381
|
+
|
|
382
|
+
CREATE OR REPLACE FUNCTION store_request_refund(uuid, text, timestamptz, bigint) RETURNS boolean
|
|
383
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp
|
|
384
|
+
AS $refund$
|
|
385
|
+
DECLARE
|
|
386
|
+
inserted integer;
|
|
387
|
+
BEGIN
|
|
388
|
+
INSERT INTO public.store_refund_reviews (case_id, order_id, requested_by, requested_at, amount)
|
|
389
|
+
SELECT $1, orders.order_id, session_user, $3, $4
|
|
390
|
+
FROM public.store_orders AS orders
|
|
391
|
+
JOIN public.pagaqr_confirmations AS confirmation USING (order_id)
|
|
392
|
+
WHERE orders.order_id = $2 AND confirmation.confirmed_at <= $3 AND $4 > 0 AND $4 <= confirmation.amount
|
|
393
|
+
ON CONFLICT DO NOTHING;
|
|
394
|
+
GET DIAGNOSTICS inserted = ROW_COUNT;
|
|
395
|
+
RETURN inserted = 1;
|
|
396
|
+
END;
|
|
397
|
+
$refund$;
|
|
398
|
+
CREATE OR REPLACE FUNCTION store_approve_refund(uuid, timestamptz) RETURNS boolean
|
|
399
|
+
LANGUAGE sql SECURITY DEFINER SET search_path = pg_catalog, pg_temp
|
|
400
|
+
AS $refund$
|
|
401
|
+
WITH saved AS (
|
|
402
|
+
UPDATE public.store_refund_reviews SET approved_by = session_user, approved_at = $2
|
|
403
|
+
WHERE case_id = $1 AND approved_at IS NULL AND requested_at <= $2
|
|
404
|
+
AND requested_by <> session_user
|
|
405
|
+
RETURNING 1
|
|
406
|
+
)
|
|
407
|
+
SELECT EXISTS (SELECT 1 FROM saved)
|
|
408
|
+
$refund$;
|
|
409
|
+
CREATE OR REPLACE FUNCTION store_record_refund_result(uuid, timestamptz, text, uuid) RETURNS boolean
|
|
410
|
+
LANGUAGE sql SECURITY DEFINER SET search_path = pg_catalog, pg_temp
|
|
411
|
+
AS $refund$
|
|
412
|
+
WITH saved AS (
|
|
413
|
+
UPDATE public.store_refund_reviews
|
|
414
|
+
SET resolved_by = session_user, resolved_at = $2, outcome = $3, receipt_ref = $4
|
|
415
|
+
WHERE case_id = $1 AND resolved_at IS NULL AND approved_at <= $2 AND approved_by = session_user
|
|
416
|
+
RETURNING 1
|
|
417
|
+
)
|
|
418
|
+
SELECT EXISTS (SELECT 1 FROM saved)
|
|
419
|
+
$refund$;
|
|
420
|
+
REVOKE ALL ON FUNCTION store_request_refund(uuid, text, timestamptz, bigint) FROM PUBLIC;
|
|
421
|
+
REVOKE ALL ON FUNCTION store_approve_refund(uuid, timestamptz) FROM PUBLIC;
|
|
422
|
+
REVOKE ALL ON FUNCTION store_record_refund_result(uuid, timestamptz, text, uuid) FROM PUBLIC`;
|
|
423
|
+
const STORE_SCHEMA_LOCK = 4718301;
|
|
424
|
+
/** Creates the store's tables; run with the schema owner and serialize concurrent preparations. */
|
|
425
|
+
async function migrateStore(pool) {
|
|
426
|
+
const client = await pool.connect();
|
|
427
|
+
try {
|
|
428
|
+
await client.query("BEGIN");
|
|
429
|
+
await client.query("SELECT pg_advisory_xact_lock($1)", [STORE_SCHEMA_LOCK]);
|
|
430
|
+
await client.query([
|
|
431
|
+
SCHEMA,
|
|
432
|
+
CONSUMER_CLAIMS_SCHEMA,
|
|
433
|
+
PAYMENT_SUMMARY_SCHEMA,
|
|
434
|
+
CONTRACT_DEFAULTS_SCHEMA,
|
|
435
|
+
CANCELLATION_TERMS_SCHEMA
|
|
436
|
+
].join(";\n"));
|
|
437
|
+
await client.query("COMMIT");
|
|
438
|
+
} catch (cause) {
|
|
439
|
+
await client.query("ROLLBACK").catch(() => void 0);
|
|
440
|
+
throw cause;
|
|
441
|
+
} finally {
|
|
442
|
+
client.release();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const CONSUMER_CLAIMS_SCHEMA = `CREATE TABLE IF NOT EXISTS store_consumer_claims (
|
|
446
|
+
case_id uuid PRIMARY KEY,
|
|
447
|
+
order_id text NOT NULL REFERENCES store_orders(order_id),
|
|
448
|
+
kind text NOT NULL CHECK (kind IN ('short_quantity', 'product_mismatch', 'other_statutory_case')),
|
|
449
|
+
requested text NOT NULL CHECK (requested IN ('replacement', 'refund')),
|
|
450
|
+
offer jsonb NOT NULL,
|
|
451
|
+
offer_lines jsonb NOT NULL,
|
|
452
|
+
paid_centavos bigint NOT NULL CHECK (paid_centavos > 0),
|
|
453
|
+
sale_receipt_ref uuid NOT NULL,
|
|
454
|
+
evidence_ref uuid NOT NULL,
|
|
455
|
+
basis_ref uuid,
|
|
456
|
+
requested_by name NOT NULL,
|
|
457
|
+
requested_at timestamptz NOT NULL,
|
|
458
|
+
decision text CHECK (decision IN ('declined', 'replacement', 'refund')),
|
|
459
|
+
decided_by name,
|
|
460
|
+
decided_at timestamptz,
|
|
461
|
+
bonus_centavos bigint CHECK (bonus_centavos >= 0),
|
|
462
|
+
resolved_at timestamptz,
|
|
463
|
+
resolution_ref uuid UNIQUE,
|
|
464
|
+
UNIQUE (order_id, kind, evidence_ref),
|
|
465
|
+
CHECK ((kind = 'other_statutory_case') = (basis_ref IS NOT NULL)),
|
|
466
|
+
CHECK ((decision IS NULL) = (decided_at IS NULL) AND (decided_at IS NULL) = (decided_by IS NULL)
|
|
467
|
+
AND (decision IS NULL) = (bonus_centavos IS NULL)),
|
|
468
|
+
CHECK (decided_at IS NULL OR (decided_by <> requested_by AND decided_at >= requested_at)),
|
|
469
|
+
CHECK (decision IS NULL OR (decision = 'declined' AND bonus_centavos = 0)
|
|
470
|
+
OR (decision = requested AND bonus_centavos >= (paid_centavos + 4) / 5)),
|
|
471
|
+
CHECK ((resolved_at IS NULL) = (resolution_ref IS NULL)),
|
|
472
|
+
CHECK (resolved_at IS NULL OR (decided_at IS NOT NULL AND resolved_at >= decided_at))
|
|
473
|
+
);
|
|
474
|
+
REVOKE ALL ON store_consumer_claims FROM PUBLIC;
|
|
475
|
+
|
|
476
|
+
CREATE OR REPLACE FUNCTION store_open_consumer_claim(uuid, text, text, text, uuid, uuid, timestamptz)
|
|
477
|
+
RETURNS boolean LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp
|
|
478
|
+
AS $claim$
|
|
479
|
+
DECLARE
|
|
480
|
+
inserted integer;
|
|
481
|
+
BEGIN
|
|
482
|
+
INSERT INTO public.store_consumer_claims
|
|
483
|
+
(case_id, order_id, kind, requested, offer, offer_lines, paid_centavos, sale_receipt_ref,
|
|
484
|
+
evidence_ref, basis_ref, requested_by, requested_at)
|
|
485
|
+
SELECT $1, orders.order_id, $3, $4, orders.acceptance, orders.lines, payment.amount, ledger.sale_receipt_ref,
|
|
486
|
+
$5, $6, session_user, $7
|
|
487
|
+
FROM public.store_orders AS orders
|
|
488
|
+
JOIN public.pagaqr_confirmations AS payment USING (order_id)
|
|
489
|
+
JOIN public.pagaqr_attempts AS attempt ON attempt.attempt_id = payment.attempt_id
|
|
490
|
+
JOIN public.store_payment_ledger_refs AS ledger ON ledger.order_id = orders.order_id
|
|
491
|
+
WHERE orders.order_id = $2 AND payment.confirmed_at <= $7
|
|
492
|
+
AND orders.version = attempt.order_version AND orders.acceptance->>'orderVersion' = orders.version::text
|
|
493
|
+
AND orders.acceptance->>'totalCentavos' = payment.amount::text
|
|
494
|
+
AND $3 IN ('short_quantity', 'product_mismatch', 'other_statutory_case')
|
|
495
|
+
AND ($3 = 'other_statutory_case') = ($6 IS NOT NULL) AND $4 IN ('replacement', 'refund')
|
|
496
|
+
ON CONFLICT DO NOTHING;
|
|
497
|
+
GET DIAGNOSTICS inserted = ROW_COUNT;
|
|
498
|
+
RETURN inserted = 1;
|
|
499
|
+
END;
|
|
500
|
+
$claim$;
|
|
501
|
+
CREATE OR REPLACE FUNCTION store_decide_consumer_claim(uuid, timestamptz, text, bigint)
|
|
502
|
+
RETURNS boolean LANGUAGE sql SECURITY DEFINER SET search_path = pg_catalog, pg_temp
|
|
503
|
+
AS $claim$
|
|
504
|
+
WITH saved AS (
|
|
505
|
+
UPDATE public.store_consumer_claims SET decision = $3, decided_by = session_user,
|
|
506
|
+
decided_at = $2, bonus_centavos = $4
|
|
507
|
+
WHERE case_id = $1 AND decided_at IS NULL AND requested_by <> session_user AND requested_at <= $2
|
|
508
|
+
AND (($3 = 'declined' AND $4 = 0) OR ($3 = requested AND $4 >= (paid_centavos + 4) / 5))
|
|
509
|
+
RETURNING 1
|
|
510
|
+
)
|
|
511
|
+
SELECT EXISTS (SELECT 1 FROM saved)
|
|
512
|
+
$claim$;
|
|
513
|
+
CREATE OR REPLACE FUNCTION store_resolve_consumer_claim(uuid, timestamptz, uuid)
|
|
514
|
+
RETURNS boolean LANGUAGE sql SECURITY DEFINER SET search_path = pg_catalog, pg_temp
|
|
515
|
+
AS $claim$
|
|
516
|
+
WITH saved AS (
|
|
517
|
+
UPDATE public.store_consumer_claims SET resolved_at = $2, resolution_ref = $3
|
|
518
|
+
WHERE case_id = $1 AND resolved_at IS NULL AND decided_at <= $2 AND decided_by = session_user
|
|
519
|
+
RETURNING 1
|
|
520
|
+
)
|
|
521
|
+
SELECT EXISTS (SELECT 1 FROM saved)
|
|
522
|
+
$claim$;
|
|
523
|
+
REVOKE ALL ON FUNCTION store_open_consumer_claim(uuid, text, text, text, uuid, uuid, timestamptz) FROM PUBLIC;
|
|
524
|
+
REVOKE ALL ON FUNCTION store_decide_consumer_claim(uuid, timestamptz, text, bigint) FROM PUBLIC;
|
|
525
|
+
REVOKE ALL ON FUNCTION store_resolve_consumer_claim(uuid, timestamptz, uuid) FROM PUBLIC`;
|
|
526
|
+
const PAYMENT_SUMMARY_SCHEMA = `
|
|
527
|
+
ALTER TABLE store_privacy_consents DROP CONSTRAINT IF EXISTS store_privacy_consents_purpose_check;
|
|
528
|
+
ALTER TABLE store_privacy_consents ADD CONSTRAINT store_privacy_consents_purpose_check
|
|
529
|
+
CHECK (purpose IN ('send_order_charge', 'optional_payment_summary'))`;
|
|
530
|
+
const CONTRACT_DEFAULTS_SCHEMA = `
|
|
531
|
+
CREATE TABLE IF NOT EXISTS store_contract_defaults (
|
|
532
|
+
case_id uuid PRIMARY KEY,
|
|
533
|
+
order_id text NOT NULL REFERENCES store_orders(order_id),
|
|
534
|
+
occurred_on date NOT NULL,
|
|
535
|
+
purge_on date GENERATED ALWAYS AS ((occurred_on + INTERVAL '72 months')::date) STORED
|
|
536
|
+
);
|
|
537
|
+
CREATE INDEX IF NOT EXISTS store_contract_defaults_due ON store_contract_defaults (purge_on, case_id);
|
|
538
|
+
REVOKE ALL ON store_contract_defaults FROM PUBLIC`;
|
|
539
|
+
const CANCELLATION_TERMS_SCHEMA = `
|
|
540
|
+
CREATE TABLE IF NOT EXISTS store_privacy_cancellation_terms (
|
|
541
|
+
case_id uuid PRIMARY KEY REFERENCES store_privacy_requests(case_id),
|
|
542
|
+
basis_ref uuid NOT NULL,
|
|
543
|
+
period_from date NOT NULL,
|
|
544
|
+
period_value integer NOT NULL CHECK (period_value > 0),
|
|
545
|
+
period_unit text NOT NULL CHECK (period_unit IN ('days', 'months')),
|
|
546
|
+
blocked_until timestamptz NOT NULL
|
|
547
|
+
);
|
|
548
|
+
REVOKE ALL ON store_privacy_cancellation_terms FROM PUBLIC;
|
|
549
|
+
CREATE TABLE IF NOT EXISTS store_privacy_cancellation_reviews (
|
|
550
|
+
case_id uuid NOT NULL REFERENCES store_privacy_requests(case_id),
|
|
551
|
+
checked_at timestamptz NOT NULL,
|
|
552
|
+
datasets jsonb NOT NULL CHECK (jsonb_typeof(datasets) = 'array'),
|
|
553
|
+
PRIMARY KEY (case_id, checked_at)
|
|
554
|
+
);
|
|
555
|
+
REVOKE ALL ON store_privacy_cancellation_reviews FROM PUBLIC`;
|
|
556
|
+
/** Grants only the storefront permissions used by the generated application. */
|
|
557
|
+
async function grantStoreApplicationRole(pool, role) {
|
|
558
|
+
const to = escapeIdentifier(role);
|
|
559
|
+
await pool.query(`GRANT USAGE ON SCHEMA public TO ${to}`);
|
|
560
|
+
await pool.query(`GRANT SELECT, INSERT ON store_orders, store_privacy_notices, store_privacy_consents, store_order_support TO ${to}`);
|
|
561
|
+
await pool.query(`GRANT UPDATE (version, lines, total_centavos, cancelled, fulfilled_at) ON store_orders TO ${to}`);
|
|
562
|
+
}
|
|
563
|
+
// ../../test/setup/document-scripts.ts
|
|
564
|
+
/** Inspect the script elements parsed by the HTML tokenizer. Comments and text are not elements. */
|
|
565
|
+
function documentScriptNonces(html) {
|
|
566
|
+
const nonces = [];
|
|
567
|
+
const pending = [parse(html)];
|
|
568
|
+
while (pending.length > 0) {
|
|
569
|
+
const node = pending.pop();
|
|
570
|
+
if (!node) break;
|
|
571
|
+
if ("tagName" in node && node.tagName === "script") nonces.push(node.attrs.find(({ name }) => name === "nonce")?.value);
|
|
572
|
+
if ("childNodes" in node) for (const child of [...node.childNodes].reverse()) pending.push(child);
|
|
573
|
+
}
|
|
574
|
+
return nonces;
|
|
575
|
+
}
|
|
576
|
+
// ../../apps/demo/src/store/buyer-session.ts
|
|
577
|
+
/**
|
|
578
|
+
* The buyer's session: 128 random bits in a cookie the page's scripts cannot read. An order keeps only the SHA-256 of
|
|
579
|
+
* the session that created it, so the store's data never holds a session that could open an order.
|
|
580
|
+
*/
|
|
581
|
+
/**
|
|
582
|
+
* Over HTTPS the cookie carries the __Host- prefix: the browser then refuses one set by a parent domain or another
|
|
583
|
+
* path, so nobody but this host can plant a session on the buyer.
|
|
584
|
+
*/
|
|
585
|
+
const buyerCookieName = (secure) => secure ? "__Host-pagaqr_buyer" : "pagaqr_buyer";
|
|
586
|
+
const newBuyerSession = () => randomBytes(16).toString("base64url");
|
|
587
|
+
// ../../apps/demo/src/store/order-id.ts
|
|
588
|
+
const ORDER_IDEMPOTENCY = {
|
|
589
|
+
header: "pagaqr-order-idempotency",
|
|
590
|
+
version: "buyer-key-v1"
|
|
591
|
+
};
|
|
592
|
+
// ../../apps/demo/dev/verificar-despliegue.mjs
|
|
593
|
+
/** True when the header carries exactly private and no-store, however the platform spaces them. */
|
|
594
|
+
const privateNoStore = (headers) => (headers.get("cache-control") ?? "").split(",").map((directive) => directive.trim().toLowerCase()).sort().join(",") === "no-store,private";
|
|
595
|
+
async function verifyDeployment(target, options = {}) {
|
|
596
|
+
const { canonical, apiOnly, fetcher = fetch, report, signal, product = {
|
|
597
|
+
id: "taza-barro",
|
|
598
|
+
cents: 8500
|
|
599
|
+
}, diagnosticOrder } = options;
|
|
600
|
+
const origin = new URL(target);
|
|
601
|
+
if (origin.pathname !== "/" || origin.search || origin.hash || origin.username || origin.password) throw new Error("Pass only the origin: scheme, host and port, without a path");
|
|
602
|
+
const STORE = origin.origin;
|
|
603
|
+
const ORIGIN = canonical ? new URL(canonical).origin : STORE;
|
|
604
|
+
const https = origin.protocol === "https:";
|
|
605
|
+
const results = [];
|
|
606
|
+
const check = (name, ok, detail = "") => {
|
|
607
|
+
const result = {
|
|
608
|
+
name,
|
|
609
|
+
ok,
|
|
610
|
+
...detail ? { detail } : {}
|
|
611
|
+
};
|
|
612
|
+
results.push(result);
|
|
613
|
+
report?.(result);
|
|
614
|
+
};
|
|
615
|
+
const call = (path, init = {}) => {
|
|
616
|
+
const timeout = AbortSignal.timeout(2e4);
|
|
617
|
+
return fetcher(STORE + path, {
|
|
618
|
+
...init,
|
|
619
|
+
redirect: "manual",
|
|
620
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout
|
|
621
|
+
});
|
|
622
|
+
};
|
|
623
|
+
const health = await call("/api/health");
|
|
624
|
+
check("salud → 200 sin caché", health.status === 200 && (health.headers.get("cache-control") ?? "").includes("no-store"), `HTTP ${String(health.status)}`);
|
|
625
|
+
if (apiOnly) {
|
|
626
|
+
const res = await call("/api/health");
|
|
627
|
+
check("cabeceras de la API", res.headers.get("x-content-type-options") === "nosniff" && res.headers.get("referrer-policy") === "same-origin" && (!https || /max-age=\d{7,}/.test(res.headers.get("strict-transport-security") ?? "")), https ? "nosniff, same-origin y HSTS" : "nosniff y same-origin");
|
|
628
|
+
}
|
|
629
|
+
const nonces = [];
|
|
630
|
+
for (const path of apiOnly ? [] : ["/", "/carrito"]) {
|
|
631
|
+
const res = await call(path);
|
|
632
|
+
const policy = res.headers.get("content-security-policy") ?? "";
|
|
633
|
+
const nonce = /'nonce-([^']+)'/.exec(policy)?.[1];
|
|
634
|
+
const scripts = documentScriptNonces(await res.text());
|
|
635
|
+
const signed = scripts.filter((value) => value === nonce).length;
|
|
636
|
+
nonces.push(nonce);
|
|
637
|
+
check(`CSP de ${path} con nonce en cada <script>`, res.status === 200 && Boolean(nonce) && scripts.length > 0 && signed === scripts.length, `${String(signed)}/${String(scripts.length)}`);
|
|
638
|
+
check(`cabeceras de ${path}`, res.headers.get("x-content-type-options") === "nosniff" && res.headers.get("referrer-policy") === "same-origin" && (!https || /max-age=\d{7,}/.test(res.headers.get("strict-transport-security") ?? "")), https ? "nosniff, same-origin y HSTS" : "nosniff y same-origin");
|
|
639
|
+
}
|
|
640
|
+
if (!apiOnly) check("nonce distinto por documento", Boolean(nonces[0]) && nonces[0] !== nonces[1]);
|
|
641
|
+
let order = diagnosticOrder?.read();
|
|
642
|
+
let createdStatus = 201;
|
|
643
|
+
if (!order) {
|
|
644
|
+
if (diagnosticOrder && (health.status !== 200 || health.headers.get(ORDER_IDEMPOTENCY.header) !== ORDER_IDEMPOTENCY.version)) {
|
|
645
|
+
check("la tienda anuncia creación idempotente de pedidos", false);
|
|
646
|
+
return {
|
|
647
|
+
store: STORE,
|
|
648
|
+
origin: ORIGIN,
|
|
649
|
+
verifiedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
650
|
+
passed: false,
|
|
651
|
+
results
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
const attempt = diagnosticOrder?.attempt(() => ({
|
|
655
|
+
key: randomBytes(32).toString("base64url"),
|
|
656
|
+
cookie: buyerCookieName(https) + "=" + newBuyerSession()
|
|
657
|
+
}));
|
|
658
|
+
const created = await call("/api/store/orders", {
|
|
659
|
+
method: "POST",
|
|
660
|
+
headers: {
|
|
661
|
+
"content-type": "application/json",
|
|
662
|
+
Origin: ORIGIN,
|
|
663
|
+
...attempt && {
|
|
664
|
+
Cookie: attempt.cookie,
|
|
665
|
+
"Idempotency-Key": attempt.key
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
body: JSON.stringify({
|
|
669
|
+
items: [{
|
|
670
|
+
productId: product.id,
|
|
671
|
+
quantity: 1
|
|
672
|
+
}],
|
|
673
|
+
acceptedOffer: {
|
|
674
|
+
termsVersion: "2026-12-04",
|
|
675
|
+
totalCentavos: product.cents
|
|
676
|
+
}
|
|
677
|
+
})
|
|
678
|
+
});
|
|
679
|
+
createdStatus = created.status;
|
|
680
|
+
if (createdStatus === 201) {
|
|
681
|
+
const receipt = await created.json();
|
|
682
|
+
const setCookie = created.headers.get("set-cookie") ?? "";
|
|
683
|
+
const cookie = setCookie.split(";")[0];
|
|
684
|
+
order = {
|
|
685
|
+
id: receipt?.id,
|
|
686
|
+
cookie,
|
|
687
|
+
cookieVerified: (!attempt || cookie === attempt.cookie) && /(?:^|;\s*)HttpOnly(?:;|$)/i.test(setCookie) && /(?:^|;\s*)SameSite=Lax(?:;|$)/i.test(setCookie) && (!https || /(?:^|;\s*)Secure(?:;|$)/i.test(setCookie))
|
|
688
|
+
};
|
|
689
|
+
if (typeof order.id === "string" && order.id && cookie) diagnosticOrder?.save(order);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
order ??= {
|
|
693
|
+
id: "",
|
|
694
|
+
cookie: "",
|
|
695
|
+
cookieVerified: false
|
|
696
|
+
};
|
|
697
|
+
const { cookie } = order;
|
|
698
|
+
check("crear pedido → 201 con cookie HttpOnly y SameSite=Lax", createdStatus === 201 && Boolean(order.id && cookie && order.cookieVerified), `HTTP ${String(createdStatus)}`);
|
|
699
|
+
const foreign = await call("/api/store/orders", {
|
|
700
|
+
method: "POST",
|
|
701
|
+
headers: {
|
|
702
|
+
"content-type": "application/json",
|
|
703
|
+
Origin: "https://evil.example"
|
|
704
|
+
},
|
|
705
|
+
body: JSON.stringify({ items: [{
|
|
706
|
+
productId: product.id,
|
|
707
|
+
quantity: 1
|
|
708
|
+
}] })
|
|
709
|
+
});
|
|
710
|
+
check("crear pedido desde otro origen → 403", foreign.status === 403, `HTTP ${String(foreign.status)}`);
|
|
711
|
+
const orderPath = apiOnly ? "/api/store/orders/" : "/pedido/";
|
|
712
|
+
const own = await call(orderPath + String(order.id), { headers: { cookie } });
|
|
713
|
+
const ownBody = await own.text();
|
|
714
|
+
check(apiOnly ? "el pedido abre con su sesión" : "la página del pedido abre con su sesión y monta el checkout", own.status === 200 && (apiOnly ? JSON.parse(ownBody).id === order.id : ownBody.includes("class=\"pagaqr-checkout\"")), `HTTP ${String(own.status)}`);
|
|
715
|
+
const stranger = await call(orderPath + String(order.id));
|
|
716
|
+
const missing = await call(orderPath + "AAAAAAAAAAAAAAAAAAAAAA");
|
|
717
|
+
check("pedido ajeno y pedido inexistente: el mismo 404", stranger.status === 404 && missing.status === 404, `${String(stranger.status)}/${String(missing.status)}`);
|
|
718
|
+
const statusPath = `/api/pagaqr/orders/${String(order.id)}/status`;
|
|
719
|
+
const strangerStatus = await call(statusPath);
|
|
720
|
+
const missingStatus = await call("/api/pagaqr/orders/AAAAAAAAAAAAAAAAAAAAAA/status");
|
|
721
|
+
check("estado ajeno e inexistente: mismo 404, mismo cuerpo y no-store", strangerStatus.status === 404 && await strangerStatus.text() === await missingStatus.text() && privateNoStore(strangerStatus.headers));
|
|
722
|
+
const pending = await call(statusPath, { headers: { cookie } });
|
|
723
|
+
check("estado del pedido nuevo → pending", pending.status === 200 && JSON.stringify(await pending.json()) === "{\"state\":\"pending\"}");
|
|
724
|
+
const preview = await call("/vista-de-pago");
|
|
725
|
+
check("la vista de pago de desarrollo no existe → 404", preview.status === 404, `HTTP ${String(preview.status)}`);
|
|
726
|
+
const forged = await call("/api/pagaqr/webhooks/pey", {
|
|
727
|
+
method: "POST",
|
|
728
|
+
headers: {
|
|
729
|
+
"content-type": "application/json",
|
|
730
|
+
"webhook-id": "msg_verificacion",
|
|
731
|
+
"webhook-timestamp": String(Math.floor(Date.now() / 1e3)),
|
|
732
|
+
"webhook-signature": "v1,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
|
|
733
|
+
},
|
|
734
|
+
body: JSON.stringify({
|
|
735
|
+
type: "transaction.paid",
|
|
736
|
+
data: { id: "falso" }
|
|
737
|
+
})
|
|
738
|
+
});
|
|
739
|
+
check("aviso con firma falsa → 401", forged.status === 401, `HTTP ${String(forged.status)}`);
|
|
740
|
+
const cron = await call("/api/pagaqr/cron");
|
|
741
|
+
check("cron sin secreto → 401, sin ejecutar", cron.status === 401, `HTTP ${String(cron.status)}`);
|
|
742
|
+
const put = await call("/api/pagaqr/charge", { method: "PUT" });
|
|
743
|
+
check("PUT al cobro → 405 con Allow y no-store", put.status === 405 && put.headers.get("allow") === "POST" && privateNoStore(put.headers));
|
|
744
|
+
const server = await call("/_next/server/app/page.js");
|
|
745
|
+
check("los archivos del servidor no se publican → 404", server.status === 404, `HTTP ${String(server.status)}`);
|
|
746
|
+
return {
|
|
747
|
+
store: STORE,
|
|
748
|
+
origin: ORIGIN,
|
|
749
|
+
verifiedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
750
|
+
passed: results.every((result) => result.ok),
|
|
751
|
+
results
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
async function main() {
|
|
755
|
+
const args = process.argv.slice(2);
|
|
756
|
+
const option = (name) => {
|
|
757
|
+
const at = args.indexOf(name);
|
|
758
|
+
return at >= 0 ? args[at + 1] : void 0;
|
|
759
|
+
};
|
|
760
|
+
const evidencePath = option("--evidencia");
|
|
761
|
+
const canonical = option("--origen");
|
|
762
|
+
const apiOnly = args.includes("--api");
|
|
763
|
+
const VALUED = /* @__PURE__ */ new Set(["--evidencia", "--origen"]);
|
|
764
|
+
const target = args.find((arg, index) => !arg.startsWith("--") && !VALUED.has(args[index - 1] ?? ""));
|
|
765
|
+
if (!target) throw new Error("Pass the store's public origin, for example https://tienda.example");
|
|
766
|
+
const evidence = await verifyDeployment(target, {
|
|
767
|
+
canonical,
|
|
768
|
+
apiOnly,
|
|
769
|
+
report: ({ name, ok, detail }) => {
|
|
770
|
+
process.stdout.write((ok ? "OK " : "FAIL") + " " + name + (detail ? " · " + detail : "") + "\n");
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
const passed = evidence.results.filter((result) => result.ok).length;
|
|
774
|
+
process.stdout.write("\n" + String(passed) + " de " + String(evidence.results.length) + " comprobaciones en verde\n");
|
|
775
|
+
if (evidencePath) writeFileSync(evidencePath, JSON.stringify(evidence, null, 2) + "\n");
|
|
776
|
+
process.exitCode = evidence.passed ? 0 : 1;
|
|
777
|
+
}
|
|
778
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main().catch(() => {
|
|
779
|
+
process.stderr.write("No se pudo completar la verificación del despliegue.\n");
|
|
780
|
+
process.exitCode = 1;
|
|
781
|
+
});
|
|
782
|
+
// scripts/setup-runtime.mjs
|
|
783
|
+
function pool(connectionString) {
|
|
784
|
+
const database = new pg.Pool({
|
|
785
|
+
connectionString,
|
|
786
|
+
connectionTimeoutMillis: 5e3,
|
|
787
|
+
statement_timeout: 3e4,
|
|
788
|
+
lock_timeout: 1e4,
|
|
789
|
+
enableChannelBinding: true
|
|
790
|
+
});
|
|
791
|
+
database.on("error", () => void 0);
|
|
792
|
+
return database;
|
|
793
|
+
}
|
|
794
|
+
async function ready(applicationUrl) {
|
|
795
|
+
const app = pool(applicationUrl);
|
|
796
|
+
try {
|
|
797
|
+
await assertApplicationDatabase(app);
|
|
798
|
+
return true;
|
|
799
|
+
} catch {
|
|
800
|
+
return false;
|
|
801
|
+
} finally {
|
|
802
|
+
await app.end();
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
async function prepare(ownerUrl, applicationUrl) {
|
|
806
|
+
const owner = pool(ownerUrl);
|
|
807
|
+
const app = pool(applicationUrl);
|
|
808
|
+
const url = new URL(applicationUrl);
|
|
809
|
+
const role = decodeURIComponent(url.username);
|
|
810
|
+
const password = decodeURIComponent(url.password);
|
|
811
|
+
if (!/^pagaqr_app_[0-9a-f]{20}$/.test(role) || !/^[0-9a-f]{64}$/.test(password)) throw new Error("Invalid generated application role");
|
|
812
|
+
try {
|
|
813
|
+
const { client, done } = await checkout(owner);
|
|
814
|
+
try {
|
|
815
|
+
await client.query("BEGIN");
|
|
816
|
+
await client.query("SELECT pg_advisory_xact_lock(hashtext($1))", [role]);
|
|
817
|
+
const existing = await client.query("SELECT current_user = $1 AS same_owner, EXISTS (SELECT 1 FROM pg_roles WHERE rolname = $1) AS available", [role]);
|
|
818
|
+
if (existing.rows[0]?.same_owner) throw new Error("Use a separate database owner");
|
|
819
|
+
if (!existing.rows[0]?.available) await client.query("CREATE ROLE " + pg.escapeIdentifier(role) + " LOGIN PASSWORD " + pg.escapeLiteral(password));
|
|
820
|
+
else await app.query("SELECT 1");
|
|
821
|
+
await client.query("COMMIT");
|
|
822
|
+
} catch (cause) {
|
|
823
|
+
await client.query("ROLLBACK").catch(() => void 0);
|
|
824
|
+
throw cause;
|
|
825
|
+
} finally {
|
|
826
|
+
done();
|
|
827
|
+
}
|
|
828
|
+
await migrate(owner);
|
|
829
|
+
await migrateStore(owner);
|
|
830
|
+
await grantApplicationRole(owner, role);
|
|
831
|
+
await grantStoreApplicationRole(owner, role);
|
|
832
|
+
await assertApplicationDatabase(app);
|
|
833
|
+
} finally {
|
|
834
|
+
await Promise.all([owner.end(), app.end()]);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
export { prepare, ready, verifyDeployment };
|