@contentstack/delivery-plugin-interstack-reference
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Interstack reference

This is a SDK plugin for Interstack Reference App. This plugin fetches the referenced entry data through a custom field to display the content on your Contentstack website. Contentstack has its own Javascript Delivery SDK that supports this plugin which can be used to fetch the content for your page from Contentstack for Interstack Reference app.

About Interstack Reference App

Interstack Reference App allows you to fetch referenced entries in the custom field of your content type and use the entries data across multiple stacks.

How to use this plugin

To use this plugin, you need to add the includeReference call within your SDK.

  1. Install the interstack plugin from the NPM library.
npm install @contentstack/delivery-plugin-interstack-reference
  1. Import the plugin
const InterstackPlugin = require("@contentstack/delivery-plugin-interstack-reference");
  1. Create an Interstack Reference App plugin as shown below. You must provide the stack API Key and Delivery Token of all the referred stack.
function main() {
    const interstack = new InterstackPlugin([
        {
            api_key: "blt53ed****888672",
            delivery_token: "cs9b84666******c49f48",
        },
        {
            api_key: "blt7a********053b38",
            delivery_token: "cs47178********e5ba15e",
        },
    ]);
}
  1. Now, create a new stack and call the plugin within this function. This will basically fetch the plugin details and attach it with the Contentstack data.
const Stack = contentstack.Stack({
    api_key: "bltc18****3d910",
    delivery_token: "csc030300****8914a00",
    environment: "dev",
    plugins: [interstack], // Here we have added the plugin
});
  1. To select the entry which is being used in the custom field, you will have to create a query and add the field_uid of the custom field inside includeReference() method.
const query = Stack.ContentType("cs1")
    .Query()
    .includeReference("custom")
    .toJSON();
  1. Now, to find the content you need to add the below function:
query
    .find()
    .then((res) => {
        console.log(JSON.stringify(res, null, 2));
    })
    .catch((err) => console.error(err));

Example Code:

const InterstackPlugin = require("@contentstack/delivery-plugin-interstack-reference");

function main() {
    const interstack = new InterstackPlugin([
        {
            api_key: "blt53ed***8672",
            delivery_token: "cs9b84666****efc49f48",
        },
        {
            api_key: "blt7ae6****53b38",
            delivery_token: "cs471781****7e5ba15e",
        },
    ]);

    const Stack = contentstack.Stack({
        api_key: "bltc1875****b3d910",
        delivery_token: "csc030300***8914a00",
        environment: "dev",
        plugins: [interstack],
    });

    const query = Stack.ContentType("cs1")
        .Query()
        .includeReference("custom")
        .toJSON();

    query
        .find()
        .then((res) => {
            console.log(JSON.stringify(res, null, 2));
        })
        .catch((err) => console.error(err));
}

Readme

Keywords

none

Package Sidebar

Install

npm i @contentstack/delivery-plugin-interstack-reference

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

23.3 kB

Total Files

21

Last publish

Collaborators

  • amank19
  • netraj.patel
  • sagar_kamble
  • rohan-naik
  • harshalpatel91
  • erpranavjoshi
  • shafeeqd959
  • mynk
  • kego1992
  • iyerrama29
  • uukkoji
  • cloudaccounts
  • hiteshshetty