Skip to content

Instantly share code, notes, and snippets.

View edlaver's full-sized avatar

Ed Laver edlaver

View GitHub Profile
@edlaver
edlaver / writeMetafieldFromGadgetRecord.js
Last active November 7, 2023 10:57
Add as an update effect to a Gadget record that has your metafield.
module.exports = async ({ api, record, params, logger, connections }) => {
const metafieldNamespace = "<Your metafield namespace>";
const metafieldKey = "<Your metafield key>";
const metafieldType = "json"
const metafieldOwnerId = `gid://shopify/Shop/${record.id}`; // `record.id` here is the ID of our `shop` record
const gadgetFieldName = "<The matching field name in your gadget record, e.g. myMetafield>";
// Check if record change includes our metafield data
if (record.changed(gadgetFieldName)) {
logger.info(
@edlaver
edlaver / helpPage.jsx
Created September 13, 2023 10:00
Example service to fetch a Notion record map from a cf-notion-cache worker, and render it in a Polaris container
import React from "react";
import {
Layout,
LegacyCard,
Page,
SkeletonBodyText,
SkeletonDisplayText,
TextContainer,
} from "@shopify/polaris";
@edlaver
edlaver / readme.md
Last active February 21, 2024 12:25
Getting triggered by Gadget - Trigger.dev integration with Gadget.dev 🤝

Trigger.dev is "The open source Background Jobs framework for TypeScript".

It allows you to "Create long-running Jobs directly in your codebase with features like API integrations, webhooks, scheduling and delays."

It has support for frameworks such as Next.js, Express, and Remix. But can it work with Gadget? 🤔

Turns out the answer is "Yes", and it works great!


@edlaver
edlaver / entry.worker.ts
Created September 10, 2024 09:59
Sample service worker for quick caching of GET requests
/// <reference lib="WebWorker" />
// Based on: https://github.com/jacob-ebey/remix-pwa/blob/main/app/entry.worker.ts
//// Uses a modified version of: https://github.com/dumbmatter/promise-worker-bi (updated to work with service workers)
//// Co-ordinates with the client to fetch session tokens, and redirect if reauth required.
//// Parts taken from: ./web/frontend/hooks/useAuthenticatedFetch.js in the default node template
import { json } from "@remix-run/server-runtime";
import { getUnixTime, add } from "date-fns";
import { PWBWorker } from "../libs/promise-serviceworker-bi";