|
| 1 | +<% |
| 2 | +var hookPoint = locals.scapiOcapiHookPoint || locals.systemHookPoint; |
| 3 | +var hookFunctionName = hookPoint.split('.').pop(); |
| 4 | +
|
| 5 | +// SCAPI/OCAPI hook signatures from commerce-api hook-method-details reference. |
| 6 | +// Format: { params: 'paramList', jsdoc: [{name, type, desc}] } |
| 7 | +var HOOK_SIGNATURES = { |
| 8 | + // Auth |
| 9 | + 'dw.ocapi.shop.auth.beforePOST': { |
| 10 | + params: 'authorizationHeader, authRequestType', |
| 11 | + jsdoc: [{name: 'authorizationHeader', type: 'String', desc: 'the authorization header'}, {name: 'authRequestType', type: 'dw.value.EnumValue', desc: 'guest, login, or refresh'}] |
| 12 | + }, |
| 13 | + 'dw.ocapi.shop.auth.afterPOST': { |
| 14 | + params: 'customer, authRequestType', |
| 15 | + jsdoc: [{name: 'customer', type: 'dw.customer.Customer', desc: 'the authenticated customer'}, {name: 'authRequestType', type: 'dw.value.EnumValue', desc: 'guest, login, or refresh'}] |
| 16 | + }, |
| 17 | + 'dw.ocapi.shop.auth.modifyPOSTResponse': { |
| 18 | + params: 'customer, customerResponse, authRequestType', |
| 19 | + jsdoc: [{name: 'customer', type: 'dw.customer.Customer', desc: 'the authenticated customer'}, {name: 'customerResponse', type: 'Object', desc: 'the API response document'}, {name: 'authRequestType', type: 'dw.value.EnumValue', desc: 'guest, login, or refresh'}] |
| 20 | + }, |
| 21 | + // Basket |
| 22 | + 'dw.ocapi.shop.basket.beforePOST_v2': { |
| 23 | + params: 'basketRequest', |
| 24 | + jsdoc: [{name: 'basketRequest', type: 'Object', desc: 'the basket request'}] |
| 25 | + }, |
| 26 | + 'dw.ocapi.shop.basket.afterPOST': { |
| 27 | + params: 'basket', |
| 28 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the created basket'}] |
| 29 | + }, |
| 30 | + 'dw.ocapi.shop.basket.modifyPOSTResponse': { |
| 31 | + params: 'basket, basketResponse', |
| 32 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'basketResponse', type: 'Object', desc: 'the API response document'}] |
| 33 | + }, |
| 34 | + 'dw.ocapi.shop.basket.beforePATCH': { |
| 35 | + params: 'basket, basketInput', |
| 36 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket to update'}, {name: 'basketInput', type: 'Object', desc: 'the basket update document'}] |
| 37 | + }, |
| 38 | + 'dw.ocapi.shop.basket.afterPATCH': { |
| 39 | + params: 'basket, basketInput', |
| 40 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the updated basket'}, {name: 'basketInput', type: 'Object', desc: 'the basket update document'}] |
| 41 | + }, |
| 42 | + 'dw.ocapi.shop.basket.modifyPATCHResponse': { |
| 43 | + params: 'basket, basketResponse', |
| 44 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'basketResponse', type: 'Object', desc: 'the API response document'}] |
| 45 | + }, |
| 46 | + 'dw.ocapi.shop.basket.modifyGETResponse': { |
| 47 | + params: 'basket, basketResponse', |
| 48 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'basketResponse', type: 'Object', desc: 'the API response document'}] |
| 49 | + }, |
| 50 | + 'dw.ocapi.shop.basket.validateBasket': { |
| 51 | + params: 'basketResponse, duringSubmit', |
| 52 | + jsdoc: [{name: 'basketResponse', type: 'Object', desc: 'the basket response document'}, {name: 'duringSubmit', type: 'boolean', desc: 'true if called during order submit'}] |
| 53 | + }, |
| 54 | + // Basket billing address |
| 55 | + 'dw.ocapi.shop.basket.billing_address.beforePUT': { |
| 56 | + params: 'basket, billingAddress', |
| 57 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'billingAddress', type: 'Object', desc: 'the billing address document'}] |
| 58 | + }, |
| 59 | + 'dw.ocapi.shop.basket.billing_address.afterPUT': { |
| 60 | + params: 'basket, billingAddress', |
| 61 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'billingAddress', type: 'Object', desc: 'the billing address document'}] |
| 62 | + }, |
| 63 | + // Basket items |
| 64 | + 'dw.ocapi.shop.basket.items.beforePOST': { |
| 65 | + params: 'basket, items', |
| 66 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'items', type: 'Object', desc: 'the items document'}] |
| 67 | + }, |
| 68 | + 'dw.ocapi.shop.basket.items.afterPOST': { |
| 69 | + params: 'basket, items', |
| 70 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'items', type: 'Object', desc: 'the items document'}] |
| 71 | + }, |
| 72 | + // Basket item |
| 73 | + 'dw.ocapi.shop.basket.item.beforePATCH': { |
| 74 | + params: 'basket, item', |
| 75 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'item', type: 'Object', desc: 'the item document'}] |
| 76 | + }, |
| 77 | + 'dw.ocapi.shop.basket.item.afterPATCH': { |
| 78 | + params: 'basket, item', |
| 79 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'item', type: 'Object', desc: 'the item document'}] |
| 80 | + }, |
| 81 | + 'dw.ocapi.shop.basket.item.beforeDELETE': { |
| 82 | + params: 'basket, productItemId', |
| 83 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'productItemId', type: 'String', desc: 'the product item ID'}] |
| 84 | + }, |
| 85 | + 'dw.ocapi.shop.basket.item.afterDELETE': { |
| 86 | + params: 'basket, productItemId', |
| 87 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'productItemId', type: 'String', desc: 'the product item ID'}] |
| 88 | + }, |
| 89 | + // Basket coupon |
| 90 | + 'dw.ocapi.shop.basket.coupon.beforePOST': { |
| 91 | + params: 'basket, couponItem', |
| 92 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'couponItem', type: 'Object', desc: 'the coupon item document'}] |
| 93 | + }, |
| 94 | + 'dw.ocapi.shop.basket.coupon.afterPOST': { |
| 95 | + params: 'basket, couponItem', |
| 96 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'couponItem', type: 'Object', desc: 'the coupon item document'}] |
| 97 | + }, |
| 98 | + // Basket payment instrument |
| 99 | + 'dw.ocapi.shop.basket.payment_instrument.beforePOST': { |
| 100 | + params: 'basket, paymentInstrument', |
| 101 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'paymentInstrument', type: 'Object', desc: 'the payment instrument document'}] |
| 102 | + }, |
| 103 | + 'dw.ocapi.shop.basket.payment_instrument.afterPOST': { |
| 104 | + params: 'basket, paymentInstrument', |
| 105 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'paymentInstrument', type: 'Object', desc: 'the payment instrument document'}] |
| 106 | + }, |
| 107 | + // Basket shipment |
| 108 | + 'dw.ocapi.shop.basket.shipment.beforePATCH': { |
| 109 | + params: 'basket, shipment, shipmentInfo', |
| 110 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'shipment', type: 'dw.order.Shipment', desc: 'the shipment'}, {name: 'shipmentInfo', type: 'Object', desc: 'the shipment update document'}] |
| 111 | + }, |
| 112 | + 'dw.ocapi.shop.basket.shipment.afterPATCH': { |
| 113 | + params: 'basket, shipment, shipmentInfo', |
| 114 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'shipment', type: 'dw.order.Shipment', desc: 'the shipment'}, {name: 'shipmentInfo', type: 'Object', desc: 'the shipment update document'}] |
| 115 | + }, |
| 116 | + // Basket shipment shipping address |
| 117 | + 'dw.ocapi.shop.basket.shipment.shipping_address.beforePUT': { |
| 118 | + params: 'basket, shipment, shippingAddress', |
| 119 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'shipment', type: 'dw.order.Shipment', desc: 'the shipment'}, {name: 'shippingAddress', type: 'Object', desc: 'the shipping address document'}] |
| 120 | + }, |
| 121 | + 'dw.ocapi.shop.basket.shipment.shipping_address.afterPUT': { |
| 122 | + params: 'basket, shipment, shippingAddress', |
| 123 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'shipment', type: 'dw.order.Shipment', desc: 'the shipment'}, {name: 'shippingAddress', type: 'Object', desc: 'the shipping address document'}] |
| 124 | + }, |
| 125 | + // Basket shipment shipping method |
| 126 | + 'dw.ocapi.shop.basket.shipment.shipping_method.beforePUT': { |
| 127 | + params: 'basket, shipment, shippingMethod', |
| 128 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'shipment', type: 'dw.order.Shipment', desc: 'the shipment'}, {name: 'shippingMethod', type: 'Object', desc: 'the shipping method document'}] |
| 129 | + }, |
| 130 | + 'dw.ocapi.shop.basket.shipment.shipping_method.afterPUT': { |
| 131 | + params: 'basket, shipment, shippingMethod', |
| 132 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket'}, {name: 'shipment', type: 'dw.order.Shipment', desc: 'the shipment'}, {name: 'shippingMethod', type: 'Object', desc: 'the shipping method document'}] |
| 133 | + }, |
| 134 | + // Order |
| 135 | + 'dw.ocapi.shop.order.beforePOST': { |
| 136 | + params: 'basket', |
| 137 | + jsdoc: [{name: 'basket', type: 'dw.order.Basket', desc: 'the basket to create the order from'}] |
| 138 | + }, |
| 139 | + 'dw.ocapi.shop.order.afterPOST': { |
| 140 | + params: 'order', |
| 141 | + jsdoc: [{name: 'order', type: 'dw.order.Order', desc: 'the created order'}] |
| 142 | + }, |
| 143 | + 'dw.ocapi.shop.order.modifyPOSTResponse': { |
| 144 | + params: 'order, orderResponse', |
| 145 | + jsdoc: [{name: 'order', type: 'dw.order.Order', desc: 'the order'}, {name: 'orderResponse', type: 'Object', desc: 'the API response document'}] |
| 146 | + }, |
| 147 | + 'dw.ocapi.shop.order.modifyGETResponse': { |
| 148 | + params: 'order, orderResponse', |
| 149 | + jsdoc: [{name: 'order', type: 'dw.order.Order', desc: 'the order'}, {name: 'orderResponse', type: 'Object', desc: 'the API response document'}] |
| 150 | + }, |
| 151 | + 'dw.ocapi.shop.order.validateOrder': { |
| 152 | + params: 'order', |
| 153 | + jsdoc: [{name: 'order', type: 'Object', desc: 'the order response document'}] |
| 154 | + }, |
| 155 | + // Order payment instrument |
| 156 | + 'dw.ocapi.shop.order.payment_instrument.beforePOST': { |
| 157 | + params: 'order, paymentInstrument', |
| 158 | + jsdoc: [{name: 'order', type: 'dw.order.Order', desc: 'the order'}, {name: 'paymentInstrument', type: 'Object', desc: 'the payment instrument document'}] |
| 159 | + }, |
| 160 | + 'dw.ocapi.shop.order.payment_instrument.afterPOST': { |
| 161 | + params: 'order, paymentInstrument, successfullyAuthorized', |
| 162 | + jsdoc: [{name: 'order', type: 'dw.order.Order', desc: 'the order'}, {name: 'paymentInstrument', type: 'Object', desc: 'the payment instrument document'}, {name: 'successfullyAuthorized', type: 'boolean', desc: 'true if the payment was authorized'}] |
| 163 | + }, |
| 164 | + // Customer |
| 165 | + 'dw.ocapi.shop.customer.beforePOST': { |
| 166 | + params: 'registration', |
| 167 | + jsdoc: [{name: 'registration', type: 'Object', desc: 'the customer registration document'}] |
| 168 | + }, |
| 169 | + 'dw.ocapi.shop.customer.afterPOST': { |
| 170 | + params: 'customer, registration', |
| 171 | + jsdoc: [{name: 'customer', type: 'dw.customer.Customer', desc: 'the created customer'}, {name: 'registration', type: 'Object', desc: 'the customer registration document'}] |
| 172 | + }, |
| 173 | + 'dw.ocapi.shop.customer.modifyGETResponse': { |
| 174 | + params: 'customer, customerResponse', |
| 175 | + jsdoc: [{name: 'customer', type: 'dw.customer.Customer', desc: 'the customer'}, {name: 'customerResponse', type: 'Object', desc: 'the API response document'}] |
| 176 | + }, |
| 177 | + 'dw.ocapi.shop.customer.modifyPOSTResponse': { |
| 178 | + params: 'customer, customerResponse', |
| 179 | + jsdoc: [{name: 'customer', type: 'dw.customer.Customer', desc: 'the customer'}, {name: 'customerResponse', type: 'Object', desc: 'the API response document'}] |
| 180 | + }, |
| 181 | + // Product |
| 182 | + 'dw.ocapi.shop.product.modifyGETResponse': { |
| 183 | + params: 'product, productResponse', |
| 184 | + jsdoc: [{name: 'product', type: 'dw.catalog.Product', desc: 'the product'}, {name: 'productResponse', type: 'Object', desc: 'the API response document'}] |
| 185 | + }, |
| 186 | + // Product search |
| 187 | + 'dw.ocapi.shop.product_search.modifyGETResponse': { |
| 188 | + params: 'searchResponse', |
| 189 | + jsdoc: [{name: 'searchResponse', type: 'Object', desc: 'the API response document'}] |
| 190 | + } |
| 191 | +}; |
| 192 | +
|
| 193 | +// Look up signature or generate a generic one |
| 194 | +var sig = HOOK_SIGNATURES[hookPoint]; |
| 195 | +if (!sig) { |
| 196 | + // Fallback: generic signature based on method pattern |
| 197 | + if (hookFunctionName.indexOf('modifyGET') === 0 || hookFunctionName.indexOf('modifyPOST') === 0 || hookFunctionName.indexOf('modifyPATCH') === 0 || hookFunctionName.indexOf('modifyPUT') === 0 || hookFunctionName.indexOf('modifyDELETE') === 0) { |
| 198 | + sig = {params: 'object, response', jsdoc: [{name: 'object', type: 'Object', desc: 'the object being processed'}, {name: 'response', type: 'Object', desc: 'the API response document'}]}; |
| 199 | + } else if (hookFunctionName.indexOf('validate') === 0) { |
| 200 | + sig = {params: 'response', jsdoc: [{name: 'response', type: 'Object', desc: 'the response document'}]}; |
| 201 | + } else if (hookFunctionName.indexOf('before') === 0 || hookFunctionName.indexOf('after') === 0) { |
| 202 | + sig = {params: 'object', jsdoc: [{name: 'object', type: 'Object', desc: 'the object being processed'}]}; |
| 203 | + } else { |
| 204 | + sig = {params: 'object', jsdoc: [{name: 'object', type: 'Object', desc: 'the object being processed'}]}; |
| 205 | + } |
| 206 | +} |
| 207 | +-%> |
| 208 | + |
| 209 | +<% if (hookType === 'scapi-ocapi') { %> |
| 210 | +/** |
| 211 | + * SCAPI/OCAPI Hook - <%= hookPoint %> |
| 212 | + * |
| 213 | +<% sig.jsdoc.forEach(function(p) { -%> |
| 214 | + * @param {<%= p.type %>} <%= p.name %> - <%= p.desc %> |
| 215 | +<% }); -%> |
| 216 | + */ |
| 217 | +exports.<%= hookFunctionName %> = function (<%= sig.params %>) { |
| 218 | + var log = Logger.getLogger('<%= hookName %>', '<%= cartridgeName %>'); |
| 219 | + log.info('<%= hookFunctionName %> hook called'); |
| 220 | +
|
| 221 | + try { |
| 222 | + // TODO: Implement hook logic |
| 223 | +
|
| 224 | + } catch (e) { |
| 225 | + log.error('<%= hookFunctionName %> hook error: ' + e.message); |
| 226 | + return new Status( |
| 227 | + Status.ERROR, |
| 228 | + '<%= hookFunctionName.toUpperCase() %>_ERROR', |
| 229 | + e.message |
| 230 | + ); |
| 231 | + } |
| 232 | +
|
| 233 | + // WARNING: Returning Status.OK will skip the system implementation |
| 234 | + // and all subsequent hooks for this extension point. |
| 235 | + // Only uncomment if you intentionally want to override system behavior. |
| 236 | + // return new Status(Status.OK); |
| 237 | +}; |
| 238 | +<% } else { %> |
| 239 | +/** |
| 240 | + * System Hook Implementation - <%= hookPoint %> |
| 241 | + * |
| 242 | + * @param {dw.order.Basket|dw.order.Order|Object} object - The object being processed |
| 243 | + * @returns {dw.system.Status} - Status object |
| 244 | + */ |
| 245 | +exports.<%= hookFunctionName %> = function (object) { |
| 246 | + var log = Logger.getLogger('<%= hookName %>', '<%= cartridgeName %>'); |
| 247 | + log.info('<%= hookFunctionName %> system hook called'); |
| 248 | +
|
| 249 | + try { |
| 250 | + // TODO: Implement hook logic |
| 251 | +
|
| 252 | + } catch (e) { |
| 253 | + log.error('<%= hookFunctionName %> hook error: ' + e.message); |
| 254 | + return new Status( |
| 255 | + Status.ERROR, |
| 256 | + '<%= hookFunctionName.toUpperCase() %>_ERROR', |
| 257 | + e.message |
| 258 | + ); |
| 259 | + } |
| 260 | +
|
| 261 | + return new Status(Status.OK); |
| 262 | +}; |
| 263 | +<% } %> |
0 commit comments