Orchard CMS Custom Data Importer - orchardcms

I have custom code that reads a bunch of xml documents and creates a custom data import recipe that I upload using the Import/Export module in Orchard. The imported documents are of a content type "Api Documentation" that I created using the Orchard admin UI. Now, I would like to make this recipe file generation code part of a custom Orchard module (if that is the right approach, I am not sure) and let the admin user do the following:
Use a form in the admin Dashboard section to upload the xml documents that need to be run through the recipe file generator
That form submits the recipe file to the Import/Export module, so that it can perform its import process as usual
What would be the best approach to handle this? I am not even sure that creating a custom module is the right approach. If there are other extensibility options that I should take advantage of, that would be great to know.

The IImportExportService interface has a member called Import:
void Import(string recipeText);
Once you've generated your recipe you can call this method and it will execute the recipe and update the shell.
If you are just importing data then if I'm not mistaken you can get away without updating the shell (which you only need to do if features have been enabled or disabled) - in which case you can make a couple of calls to the IRecipeParser and IRecipeManager interfaces instead:
var recipe = _recipeParser.ParseRecipe(recipeText);
_recipeManager.Execute(recipe);
I've written something similar which does some importing/exporting so you can move pieces of content between sites; it also does some encryption so the details are hidden from prying eyes. A great place to start if is to read the source for the ImportExportService as it isn't all that complicated.

Related

Reading product metafields through Shopify ScriptTag API

I'm building a Shopify embedded application with two main points of functionality:
Upon install, product meta fields are populated with some values
Upon page load, a custom script is injected into product page through shopify ScriptTag api
The injected script displays some icon alongside the values from product meta fields.
Currently, from the product page, the injected script is having to request the meta fields from my local server, which then queries the clients shopify for before sending back the response.
Is there a way to access the meta field values directly from the product page, without having to do the above?
Thanks in advance.
The injected script only fires at page load on frontend, while accessing metafields is only possible via Liquid or Shopify API. The data flow that you have right now is the standard way of doing things in Shopify in such cases. However, considering performance implications or for whatever reasons, if you still want to achieve this, you can make use of Liquid.
Doing so can be done in 2 ways.
Provide a Liquid code snippet
Use Shopify API to add Liquid code snippet on App installation
Liquid Code Snippet
Once a user installs your app, provide them a Liquid code snippet to integrate in to their theme. That liquid code snippet should expose the Meta Fields to some JavaScript variable, that your injected script will read.
Shopify API to add Liquid code snippet
If you don't want the users to integrate the Liquid code snippet manually, then on Application install, make use of Theme Assets API to add you Liquid code snippet to the clients' active theme. This will need additional App permissions from users on install. Also factor in different available themes and removing code snippet from theme when App is uninstalled.
You haven't mentioned the resource where you will be creating metafields, but sample Liquid code snippet should look something like
<script>
var customMetaField = {shop.metafields.namespace.fieldname}
</script>
In your custom App script read the variable customMetaField. This is just a rough idea, you will need to check if the metafield namespace and the metafields exist and then output the values accordingly.
Shop Metafields

NestJS: where to place a file reader?

I have an architectural question regarding NestJS. Let's say I have a ContentModule and a BlueprintModule, both need to read json files. In both cases I would have a service that calls the repository which than should read those files. This repository should now use something like a FileReader class.
Where would i place this in NestJS? Should I create a new module for this and inject it into the ContentModule and BlueprintModule? I am a bit confused because I see this more as a util than a feature module. Should I just create a simple class in a utils or lib folder?
Would I create a repository at all if I don't have a database and instead access a JsonService from my BlueprintService and ContentService?
Any thoughts?
You can create a simple class in Utils and inject to your Contentmodule and Blueprint module.
There is no hard and strict rule to this. You can start off by adding it in a libs and then as you find more use cases you can always move it to another module.
Basic rule is, if you are not sure where things are to be placed, they get placed in libs. :)
Thanks

React scripts access management with Express (React+Node+Express)

I’m new to React, and I have trouble with finding best solution for my app.
My current (Node.js+Express+Handlebars) app has one main menu with place where I render HTML received from AJAX request made after click on menu element. Then all actions inside this element are done by proper JS script. I wanted to improve it by using React, but I have problem with permissions management.
Currently, after authentication, handlebars receive list of files which user should load and render it as src in element. If user has access to only 5 of 20 modules, he can access only proper JS files. Also, he can’t access HTML he don’t has access to.
How to manage it in React? I want to have one interface for all users, but I don’t want to store logic for all components accessible for every user. I was thinking about something like AJAX loading components for React, but how to manage it?
Is it even possible? As I understand (maybe wrong), all React components are compiled from separated JSX files to one main.js, so is it possible to add separate files with other components?
I believe that the issue that you have encountered is a crucial step on the long stairway of making something great. The solution to your problem is the balance of all the present factors and consolidation of them to cooperate on a mutually beneficial basis. I hope that solves your problem

Changing operation flow in nodejs

I am trying to create an ecommerce website in nodejs.I want it to be modular so that we can add extensions later without editing the main codebase. For example suppose I have an extension which checks if a user is requester or approver, and if he is an approver he can checkout, otherwise a approval request will be sent to corresponding approver.Suppose I emit an event when a checkout is made, then that extension can catch it and process it. But at the same time I want the normal flow to be changed. How can I do that? Should I create a checkout module extending original checkout module and override functions and make sure that extension's module is loaded ? If I do it there will be problem if two different extensions are adding features to same core module.What is the best way to do it ?
Generally speaking, there are two ways widely used to extend a web app :
Webhooks
Api
Both have their pros and cons.
What you are trying to do is possible in hook style, because the code will be execute on the server itself and you can extend some objects and modify their behavior as you want.

Serve custom javascript to browser via Node.js app

I developed a small node.js app in which I can configure conditions for a custom javascript file, which can be embedded in a webpage, and which modifies the DOM of that page in the browser on load. The configuration values are stored in MongoDB. (For sake of argument: add class "A" to DOM element with ID "B" )
I have difficulties to figure out the best way to serve requests / the JavaScript file.
Option 1 and my current implementation is:
I save a configuration in the node app and a distinct JavaScript
file is created for that configuration.
The page references that file which is hosted and served by the server.
Option 2 and where I think I want and should go is:
I saves a configuration (mongodb) NO JavaScript file is created Pages
a generic JavaScript link (for instance: api.service.com/javascript.js)
Node.js / Express app processes the request, and
returns a custom JavaScript (file?) with the correct values as saved in mongodb for that configuration
Now, while I believe this is the right way to go about it, I am unsure HOW to go about it. Any ideas and advise are very welcome!
Ps: For instance I wonder how best to authenticate or identify the origin, user and requested configuration. Shall I do this like: api.service.com/javascript.js&id="userID" - is that good practice?
Why not serve up a generic Javascript file which can take a customized json object (directly from mongodb) and apply the necessary actions? You can include the json data on the page if you really need to have everything embedded, but breaking up configuration and code is the most maintainable approach.

Resources