Setting the file. One moment.
Blocked Data Handlers · Rp Source Wordpress · wix/skills · Skills Docs
ContentsBack to the top of the page 39.41
PLUGIN READ PLANS
lib/blocked-data-handlers.js
lib/ blocked-data-handlers.js
JavaScript · 73 lines · 4 KB
// REST route at all: a profile's fulfillment supplies its own `table`, not its own
11 // handler. Exposes both of wix-wp-plugin-v2's routes -- discoverStructure (schema only)
12 // and queryStructure (real row data) -- see wix-wp-plugin-v2-client.js's header comment
13 // for why pulling real row data through this handler is still a separate per-entity
14 // decision, not implied by schema-discoverability.
15 'wix-wp-plugin-v2' : Object. freeze ({
16 kind: 'structure-bridge-plugin' ,
17 version: wixWpPluginV2Client. HANDLER_VERSION ,
18 discoverStructure: wixWpPluginV2Client.discoverStructure,
19 queryStructure: wixWpPluginV2Client.queryStructure,
20 // What a caller needs to build a legal request against a key/value table: every value
21 // column that stays unreachable until its own key column is pinned.
22 guardedValueColumns: wixWpPluginV2Client.guardedValueColumns,
23 selfTest: require ( './wix-wp-plugin-v2-client.test-fixture.js' ),
24 }),
25 // Generic across any checkout-field-editor-style WooCommerce plugin (ThemeHigh's
26 // Checkout Field Editor today, any other vendor tomorrow) — the parser only validates
27 // this pipeline's own canonical CSV shape, never a vendor-specific export format or
28 // meta-key convention. A second such plugin's profile can point its own
29 // blocked[].fulfillment.handlerId at this same id and reuse it unchanged.
30 'checkout-field-csv' : Object. freeze ({
31 kind: 'csv-upload' ,
32 version: checkoutFieldCsvParser. HANDLER_VERSION ,
33 parse: checkoutFieldCsvParser.parse,
34 selfTest: require ( './checkout-field-csv-parser.test-fixture.js' ),
35 }),
36 });
37
38 function getHandler ( handlerId ) {
39 return handlers[handlerId] || null ;
40 }
41
42 async function testOne ( handler ) {
43 if ( typeof handler.selfTest !== 'function' ) return { ready: false , reason: 'handler-self-test-missing' };
44 try {
45 // The whole handler is passed, not one arbitrarily-chosen capability, so a self-test
46 // can exercise every capability its handler actually offers (e.g. wix-wp-plugin-v2's
47 // discoverStructure AND queryStructure) -- a self-test that only ever received
48 // discoverStructure would report readiness even if queryStructure were broken.
49 const passed = await handler. selfTest (handler);
50 return passed === true ? { ready: true , reason: null } : { ready: false , reason: 'handler-self-test-failed' };
51 } catch (error) {
52 return { ready: false , reason: 'handler-self-test-failed' , error: error.message };
53 }
54 }
55
56 async function testHandler ( handlerId ) {
57 const handler = getHandler (handlerId);
58 return handler ? testOne (handler) : { ready: false , reason: 'handler-not-registered' };
59 }
60
61 // wix-wp-plugin-v2 (structure-bridge-plugin) has no manifest/case/productionReady concept
62 // to check against -- a passing
63 // self-test IS readiness. This is the only bridge-plugin-style kind this repo has left, so
64 // there is no other branch here; a future second such kind would add its own, not overload
65 // this one.
66 async function fulfillmentReadiness ( fulfillment , { registry = handlers } = {}) {
67 const handler = fulfillment && registry[fulfillment.handlerId];
68 if ( ! handler) return { ready: false , reason: 'handler-not-registered' };
69 if (handler.kind !== fulfillment.kind) return { ready: false , reason: 'handler-kind-mismatch' };
70 return testOne (handler);
71 }
72
73 module . exports = { handlers, getHandler, testHandler, fulfillmentReadiness };