|
| 1 | +import { createExpressServer } from "@trigger.dev/express"; |
| 2 | +import { TriggerClient, eventTrigger } from "@trigger.dev/sdk"; |
| 3 | +import { z } from "zod"; |
| 4 | + |
| 5 | +export const client = new TriggerClient({ |
| 6 | + id: "job-catalog", |
| 7 | + apiKey: process.env["TRIGGER_API_KEY"], |
| 8 | + apiUrl: process.env["TRIGGER_API_URL"], |
| 9 | + verbose: false, |
| 10 | + ioLogLocalEnabled: true, |
| 11 | +}); |
| 12 | + |
| 13 | +client.defineJob({ |
| 14 | + id: "redaction-example-1", |
| 15 | + name: "Redaction Example 1", |
| 16 | + version: "1.0.0", |
| 17 | + enabled: true, |
| 18 | + trigger: eventTrigger({ |
| 19 | + name: "redaction.example", |
| 20 | + }), |
| 21 | + run: async (payload, io, ctx) => { |
| 22 | + const result = await io.runTask( |
| 23 | + "task-example-1", |
| 24 | + async () => { |
| 25 | + return { |
| 26 | + id: "evt_3NYWgVI0XSgju2ur0PN22Hsu", |
| 27 | + object: "event", |
| 28 | + api_version: "2022-11-15", |
| 29 | + created: 1690473903, |
| 30 | + data: { |
| 31 | + object: { |
| 32 | + id: "ch_3NYWgVI0XSgju2ur0C2UzeKC", |
| 33 | + object: "charge", |
| 34 | + amount: 1500, |
| 35 | + amount_captured: 1500, |
| 36 | + amount_refunded: 0, |
| 37 | + application: null, |
| 38 | + application_fee: null, |
| 39 | + application_fee_amount: null, |
| 40 | + balance_transaction: "txn_3NYWgVI0XSgju2ur0qujz4Kc", |
| 41 | + billing_details: { |
| 42 | + address: { |
| 43 | + city: null, |
| 44 | + country: null, |
| 45 | + line1: null, |
| 46 | + line2: null, |
| 47 | + postal_code: null, |
| 48 | + state: null, |
| 49 | + }, |
| 50 | + email: null, |
| 51 | + name: null, |
| 52 | + phone: null, |
| 53 | + }, |
| 54 | + calculated_statement_descriptor: "WWW.TRIGGER.DEV", |
| 55 | + captured: true, |
| 56 | + created: 1690473903, |
| 57 | + currency: "usd", |
| 58 | + customer: "cus_OLD6IR3D8CJasG", |
| 59 | + description: "Subscription creation", |
| 60 | + destination: null, |
| 61 | + dispute: null, |
| 62 | + disputed: false, |
| 63 | + failure_balance_transaction: null, |
| 64 | + failure_code: null, |
| 65 | + failure_message: null, |
| 66 | + fraud_details: {}, |
| 67 | + invoice: "in_1NYWgUI0XSgju2urV5ZTEyIn", |
| 68 | + livemode: false, |
| 69 | + metadata: {}, |
| 70 | + on_behalf_of: null, |
| 71 | + order: null, |
| 72 | + outcome: { |
| 73 | + network_status: "approved_by_network", |
| 74 | + reason: null, |
| 75 | + risk_level: "normal", |
| 76 | + risk_score: 61, |
| 77 | + seller_message: "Payment complete.", |
| 78 | + type: "authorized", |
| 79 | + }, |
| 80 | + paid: true, |
| 81 | + payment_intent: "pi_3NYWgVI0XSgju2ur0fWNLexG", |
| 82 | + payment_method: "pm_1NYWgTI0XSgju2urW3aXpinM", |
| 83 | + payment_method_details: { |
| 84 | + card: { |
| 85 | + brand: "visa", |
| 86 | + checks: { |
| 87 | + address_line1_check: null, |
| 88 | + address_postal_code_check: null, |
| 89 | + cvc_check: null, |
| 90 | + }, |
| 91 | + country: "US", |
| 92 | + exp_month: 7, |
| 93 | + exp_year: 2024, |
| 94 | + fingerprint: "w6qgKDLO5EbIJ5VZ", |
| 95 | + funding: "credit", |
| 96 | + installments: null, |
| 97 | + last4: "4242", |
| 98 | + mandate: null, |
| 99 | + network: "visa", |
| 100 | + network_token: { |
| 101 | + used: false, |
| 102 | + }, |
| 103 | + three_d_secure: null, |
| 104 | + wallet: null, |
| 105 | + }, |
| 106 | + type: "card", |
| 107 | + }, |
| 108 | + receipt_email: null, |
| 109 | + receipt_number: null, |
| 110 | + receipt_url: |
| 111 | + "https://pay.stripe.com/receipts/invoices/CAcaFwoVYWNjdF8xTVJtRzRJMFhTZ2p1MnVyKLCriqYGMga_ozxgMkA6LBbrKccthI_hGdug_gXtuu_piRAvzyNVaH_aMq9mUTOl3VdNbfcH7nhFjK08?s=ap", |
| 112 | + refunded: false, |
| 113 | + review: null, |
| 114 | + shipping: null, |
| 115 | + source: null, |
| 116 | + source_transfer: null, |
| 117 | + statement_descriptor: null, |
| 118 | + statement_descriptor_suffix: null, |
| 119 | + status: "succeeded", |
| 120 | + transfer_data: null, |
| 121 | + transfer_group: null, |
| 122 | + }, |
| 123 | + }, |
| 124 | + livemode: false, |
| 125 | + pending_webhooks: 2, |
| 126 | + request: { |
| 127 | + id: "req_vtwGrzB2O98Pnc", |
| 128 | + idempotency_key: "215856c0-4f06-48eb-94c6-7ed4e839d7bc", |
| 129 | + }, |
| 130 | + type: "charge.succeeded", |
| 131 | + }; |
| 132 | + }, |
| 133 | + { |
| 134 | + redact: { |
| 135 | + paths: [ |
| 136 | + "data.object.balance_transaction", |
| 137 | + "data.object.billing_details", |
| 138 | + "data.object.this_does_not_exist", |
| 139 | + "data.object.$$$$hello", |
| 140 | + ], |
| 141 | + }, |
| 142 | + } |
| 143 | + ); |
| 144 | + |
| 145 | + await io.logger.info("Log.1", { ctx, result }); |
| 146 | + |
| 147 | + await io.wait("wait-1", 1); |
| 148 | + |
| 149 | + await io.logger.info("Log.2", { ctx, result }); |
| 150 | + }, |
| 151 | +}); |
| 152 | + |
| 153 | +createExpressServer(client); |
0 commit comments