← back to Dw Signup Fulfillment
verification/tk11114-remediation/r4.js
44 lines
'use strict';
// TK-11114 R4 helper — controlled LIVE Shopify ops for the ONE approved +dwgolive test.
// LIVE by design: DRY_RUN forced 0 so the customers/create webhook actually fires.
// Subcommands: create | get <id> | delete <id>
process.env.DRY_RUN = '0';
const path = require('path');
const shopify = require(path.join(__dirname, '..', '..', 'lib', 'shopify'));
const config = require(path.join(__dirname, '..', '..', 'lib', 'config'));
async function createCustomer() {
const ts = new Date().toISOString().replace(/[:.]/g, '-');
const email = `steve+dwgolive-tk11114-${Date.now()}@designerwallcoverings.com`;
const body = { customer: { email, first_name: 'DW GoLive', last_name: 'TK11114 Test', tags: 'tk11114-test', verified_email: true } };
const r = await shopify.request('POST', '/customers.json', body);
const c = r && r.json && r.json.customer;
if (!r.ok || !c || !c.id) { console.log(JSON.stringify({ ok: false, status: r.status, json: r.json })); process.exit(1); }
console.log(JSON.stringify({ ok: true, id: c.id, email: c.email, created_at: c.created_at, tags: c.tags }, null, 2));
}
async function getCustomer(id) {
const r = await shopify.getCustomer(id);
const c = r && r.json && r.json.customer;
let mf = null;
try { mf = await shopify.getCustomerMetafield(id, 'custom', 'sample_verified'); } catch (e) {}
let sentFlag = null;
try { sentFlag = await shopify.getCustomerMetafield(id, 'custom', 'sample_verify_sent'); } catch (e) {}
console.log(JSON.stringify({ ok: r.ok, status: r.status, id: c && c.id, email: c && c.email, tags: c && c.tags, verified_metafield: mf, sample_verify_sent: sentFlag }, null, 2));
}
async function deleteCustomer(id) {
const r = await shopify.request('DELETE', `/customers/${id}.json`, undefined);
console.log(JSON.stringify({ ok: r.ok, status: r.status, id }));
// confirm 404
const g = await shopify.getCustomer(id);
console.log(JSON.stringify({ verify_deleted: true, get_status: g.status }));
}
const [cmd, arg] = process.argv.slice(2);
if (!config.SHOPIFY_FULFILLMENT_TOKEN) { console.log(JSON.stringify({ ok: false, error: 'no fulfillment token resolved' })); process.exit(1); }
(async () => {
if (cmd === 'create') return createCustomer();
if (cmd === 'get') return getCustomer(arg);
if (cmd === 'delete') return deleteCustomer(arg);
console.log('usage: node r4.js create|get <id>|delete <id>'); process.exit(2);
})().catch(e => { console.error('r4 error:', e.message); process.exit(1); });