Skip to content

Instantly share code, notes, and snippets.

View ntotten's full-sized avatar

Nathan Totten ntotten

View GitHub Profile
import { ZuploContext, ZuploRequest, environment } from "@zuplo/runtime";
interface UserEvent {
object: "event";
type: "user.created";
data: UserData;
}
interface UserData {
const fileStream = request.body; // Stream of the file content
const reader = fileStream.getReader();
const decoder = new TextDecoder();
let firstColumnValues = [];
let leftover = ''; // Store any partial lines
const processChunk = async ({ done, value }) => {
if (done) {
// Process any remaining line in leftover
import { ZuploContext, ZuploRequest, environment } from "@zuplo/runtime";
type MyPolicyOptionsType = {
bucketName: string;
accountName: string;
};
export default async function policy(
request: ZuploRequest,
context: ZuploContext,
{
"name": "my-request-validation-inbound-policy",
"policyType": "request-validation-inbound",
"handler": {
"export": "RequestValidationInboundPolicy",
"module": "$import(@zuplo/runtime)",
"options": {
"includeRequestInLogs": false,
"logLevel": "info",
"validateBody": "reject-and-log"
import { ZuploContext, ZuploRequest } from "@zuplo/runtime";
export default async function (
request: ZuploRequest,
context: ZuploContext,
options: any,
policyName: string
) {
const url = new URL(request.url);
import { ZuploContext, ZuploRequest, environment } from "@zuplo/runtime";
// {
// "event": "some string",
// "payload": {
// "auth": {
// "email": "email"
// },
// "customFields": {},
// This was generated with ChatGTP as an expiriment. If you find this, don't trust that the
// code works. I didn't test this or anything. See: https://twitter.com/ntotten/status/1657012479942066177
class HubspotSDK {
private apiKey: string;
private baseUrl: string = 'https://api.hubapi.com';
constructor(apiKey: string) {
this.apiKey = apiKey;
}
import { ZuploContext, ZuploRequest, HttpProblems } from "@zuplo/runtime";
export default async function (
request: ZuploRequest,
context: ZuploContext
) {
if (request.user.data.isExpired === true) {
return HttpProblems.forbidden(request, context, {
detail: "This account is expired."
})
import { ZuploContext, ZuploRequest, ZoneCache, environment } from "@zuplo/runtime";
// Get environment variables
// AZURE_AD_TENENT_ID: The tenant ID of your Azure AD (UUID)
// AZURE_AD_CLIENT_ID: The client ID of the "zuplo" Azure AD application (UUID)
// AZURE_AD_CLIENT_SECRET: The secret for the "zuplo" Azure AD application
// API_HOST: The url of your Azure App service i.e. https://zup-demo1.azurewebsites.net/
const { AZURE_AD_TENENT_ID, AZURE_AD_CLIENT_ID, AZURE_AD_CLIENT_SECRET, API_HOST } = environment;
const TOKEN_CACHE_KEY = "ad-token"
import { ZuploRequest, ZuploContext, ResponseFactory, environment } from "@zuplo/runtime";
import { SegmentClient } from "./segment";
export async function postLogin(
request: ZuploRequest,
context: ZuploContext
): Promise<Response> {
if (!environment.SEGMENT_WRITE_KEY) {
throw new Error("SEGMENT_WRITE_KEY environment variable not set")
}