segment-cdp-functions
v1.0.35
Published
This library is a framework which allows one to create Segment CDP function and manager their DevOps
Downloads
5
Maintainers
Readme
Segment CDP Functions (Beta)
Introduction
Welcome to the segment-cdp-functions
NPM package. This tool is designed to bolster developers' capabilities, streamlining the creation, building, and deployment processes for Segment CDP Functions. With robust integration capabilities for Typescript, CI/CD patterns, and testing environments, our goal is to enhance the development lifecycle and ensure flawless compatibility with the Segment function environment.
Highlighted Features
- Quick Setup: Instantly set up projects and pipelines for Segment CDP Functions.
- Typescript Integration: Natively write and compile functions using Typescript.
- RollupJS Bundling: Leverage rollupJS for efficient code bundling.
- Segment Deployment Assistance: Hassle-free deployment of your bundled code to the Segment environment.
- CI/CD & Testing: Easily integrate continuous integration and continuous delivery patterns, and test your functions seamlessly.
Precautions
- Limited Functionality: Currently, only support for destination functions is available.
- Library Limitations: To ensure function compatibility, please refrain from adding external libraries to your project. The Segment function environment might not recognize them, risking potential functional disruptions.
- Accessible Methods: The code environment grants access to specific methods, including
fetch()
,atob()
, andbtoa()
.
Best Practices
- Situate all your classes within the
./src
directory. - For optimal functionality, incorporate and employ these classes within
./src/index.ts
.
Workflow
Understanding the expectations of the Segment function environment is crucial. Typically, it anticipates a single NodeJS (NodeNext) compatible code. Traditional practices might not fit these parameters. That's where our package steps in:
- Setup: Embark on your journey by initializing a fresh project and integrating all essential dependencies.
- Development: Dive into a developer-centric environment with full-fledged Typescript support.
- Compilation: Rely on rollupJS combined with Typescript to curate a code bundle that's a perfect fit for the Segment environment.
- Deployment: Transfer the resulting bundle to the Segment environment, ensuring it integrates smoothly.
Quick Start Guide
Embark on your Segment CDP Functions journey with these simple steps:
- Launch your terminal.
- Install the package using
npm i -g segment-cdp-functions
. - Create a project directory:
mkdir <project-name>
. - Navigate to it:
cd <project-name>
. - Initialize your project within the directory using:
segment-cdp-functions init
. - Explore the available Segment API functions in
./src/index.ts
. - Check out the sample
./src/slack.ts
which demonstrates sending Slack messages. - Bundle your code using:
npm run build
. This produces a deployment-ready code bundle (./<build>/index.js
) and a JSON file (./<build>/to_deploy.json
). - To deploy, acquire a segment token and save it in the
.env
file. Obtain this token from your Segment workspace by navigating: Settings > Workspace Settings > Access Management Tab > Tokens Tab > Create Token. Assign it a name and grant access asWorkspace Member
>Function Admin
. Use this token in your.env
asSEGMENT_TOKEN=<Token>
. - Deploy your function with:
npm run deploy
.
We wish you an effortless development journey with the segment-cdp-functions
package. Should you have any questions or feedback, please reach out.