Skip to content

Instantly share code, notes, and snippets.

View airhorns's full-sized avatar
🎯
Workin' on Gadget at https://gadget.dev

Harry Brundage airhorns

🎯
Workin' on Gadget at https://gadget.dev
View GitHub Profile
rip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs" "--ld-path=/nix/store/cg869jlpzrh5xgc0hcll7risc5gsk611-mold-2.1.0/bin/mold"
> = note: clang-11: error: unsupported option '--ld-path=/nix/store/cg869jlpzrh5xgc0hcll7risc5gsk611-mold-2.1.0/bin/mold'
>
>
> error: could not compile `jsonpath_lib` (lib) due to previous error
> warning: build failed, waiting for other jobs to finish...
@airhorns
airhorns / terse-default.js
Last active May 16, 2023 18:32
Gadget nextgen code snippets
import { assignInputs, validateAndSave } from "gadget";
/**
* Run Action code for create on post
* @param { import("gadget").CreatePostActionContext } context - Everything for running this action handler, like the api client, current record, params, etc. More on effect context: https://docs.gadget.dev/guides/extending-with-code#effect-context
*/
export async function run({ api, record, inputs }) {
assignInputs(record, inputs);
await validateAndSave(record);
}
00:56:50 Encountered an error:
module 'isolate_proto' has no attribute 'RegisterCronResult'
00:56:50 Traceback (most recent call last):
File "/Users/airhorns/Library/Caches/pypoetry/virtualenvs/warehouse-ACxaxuaC-py3.9/lib/python3.9/site-packages/dbt/main.py", line 136, in main
results, succeeded = handle_and_check(args)
File "/Users/airhorns/Library/Caches/pypoetry/virtualenvs/warehouse-ACxaxuaC-py3.9/lib/python3.9/site-packages/dbt/main.py", line 206, in handle_and_check
task, res = run_from_args(parsed)
File "/Users/airhorns/Library/Caches/pypoetry/virtualenvs/warehouse-ACxaxuaC-py3.9/lib/python3.9/site-packages/dbt/main.py", line 233, in run_from_args
task = parsed.cls.from_args(args=parsed)
File "/Users/airhorns/Library/Caches/pypoetry/virtualenvs/warehouse-ACxaxuaC-py3.9/lib/python3.9/site-packages/dbt/task/base.py", line 163, in from_args
@airhorns
airhorns / vite.config.js
Created January 4, 2023 20:51
Final vite.config.js code for Gadget + Shopify CLI app
import { defineConfig } from "vite";
import { dirname } from "path";
import { fileURLToPath } from "url";
import react from "@vitejs/plugin-react";
if (process.env.npm_lifecycle_event === "build" && !process.env.CI && !process.env.SHOPIFY_API_KEY) {
console.warn(
"\nBuilding the frontend app without an API key. The frontend build will not run without an API key. Set the SHOPIFY_API_KEY environment variable when running the build command.\n"
);
}
@airhorns
airhorns / Updating Gadgetized CLI App For Shopify Public App Store.md
Last active January 4, 2023 20:56
Guide for upgrading a Shopify CLI generated app to set correct iframe security headers

This document explains how to update a Shopify CLI generated application from the setup Gadget previously recommended before Dec 21, 2022, to the new setup Gadget recommends.

Why

Previously, Gadget recommended removing the web/package.json and web/shopify.web.toml files, stripping away the node.js server that served the frontend application in web/frontend. Most web hosts have functionality to serve static files in the same manner this node.js application does, as well as set up redirects and headers. Since Gadget handles the majority of the backend, this node.js backend largely duplicates Gadget functionality.

That said, it is annoying to set up each different frontend hosting provider's tooling to meet Shopify's strict iframe security requirements for apps destined for the Public App Store. Shopify requires that each application is served to the embedded app iframe with the Content-Security-Policy header set to a secure value. Read more about Shopify's iframe security requirements [her

@airhorns
airhorns / retryShopifyCall.ts
Last active June 22, 2022 20:17
Wrapper code for making calls to Shopify using `shopify-api-node` that get automatically retried when the rate limit is exceeded
import pRetry from "p-retry";
import { isArray, isNil, isObject, isString } from "lodash";
const responseFromError = (error: any): Response | undefined => {
if ("response" in error) {
const response = error.response;
if (response && "body" in response) {
return response as Response;
}
}
[4:23:42.929 PM] INFO (temporal-worker): [temporal_sdk_core::worker] Initializing worker task_queue=default
RUNS api packages/api/spec/services/auth/ResetPassword.spec.ts
[4:23:43.205 PM] INFO (temporal-worker): Worker state changed
userVisible: false
state: "RUNNING"
[4:23:43.208 PM] DEBUG (temporal-worker): [temporal_sdk_core::worker] poll_workflow_activation;
RUNS api packages/api/spec/services/auth/ResetPassword.spec.ts
[4:23:44.917 PM] DEBUG (temporal-worker): [temporal_sdk_core::workflow::workflow_tasks] Applying new workflow task from server task_token=CiQ2Yjk2MjBlMi0zYTUxLTQ0Y2ItYTkwZC0xMDZmNmRlNjE3NjUSIHNlbmQtZW1haWwtRFhJREtGNGZYYlZqUTE1MHFzT2RLGiQ2N2U4YzljZC02MjFiLTQ5YjYtODI1My1kNTg4ZjA3NGQwYTcgAigB history_length=3 start_event_id=Some(1) attempt=1 run_id=67e8c9cd-621b-49b6-8253-d588f074d0a7
userVisible: false
[4:23:44.919 PM] DEBUG (temporal-worker): [temporal_sdk_core::workflow::workflow_tasks::concurrency_manager] create_or_update machines; run_id=67e8c9cd-621b-49b6-8253-d588f
query issues {
id
name
filter timeLogs by timeSpent > 10 {
timeSpent
level
} then group by level {
sum(timeSpent)
} then filter by deletedAt is not set and publishedAt < NOW()
then sort by timeSpent Descending
#21 0.382 yarn run v1.22.5
#21 0.410 $ rm -rf packages/web/dist/* && NODE_ENV=production yarn workspace web webpack
#21 0.862 $ /app/node_modules/.bin/webpack
#21 1.823 (node:52) [DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK] DeprecationWarning: Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader
#21 1.823 (Use `node --trace-deprecation ...` to show where the warning was created)
#21 36.85 internal/fs/utils.js:628
#21 36.85 throw err;
#21 36.85 ^
#21 36.85
#21 36.85 TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received '/app/node_modules/es5-ext/string/\x00#/contains'
@airhorns
airhorns / yarn.lock
Created July 21, 2020 13:10
snowpack webpack debugging
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.8.3":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a"
integrity sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==
dependencies:
"@babel/highlight" "^7.10.4"