Commit de63ac8c4d

de63ac8c4d22e28152ef0a129aeba7c875e85f88

parent: d8907828b9

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-20 02:03 UTC

Sponsors through the krazywarez organization

- SPONSORABLE is krazywarez; sign-in looks up the visitor's sponsorship
  of any repository owner.
- Renewal finds the key's account in the organization's active
  sponsors (sponsorshipsAsMaintainer, private included, paged), with a
  token of an org owner.
- FUNDING.yml, README and CONTRIBUTING point at krazywarez.

Layout: unified · split

.github/FUNDING.yml +1 −1
@@ -1,2 +1,2 @@
1github: [ccleberg]
1github: [krazywarez]
22custom: ["https://cleberg.net/tips/"]
CONTRIBUTING.org +2 −1
@@ -80,7 +80,8 @@ Setup, once:
8080- Create a GitHub OAuth app with the callback URL =https://krz.sh/apps/orgstar/license= and
8181 put its client ID in =GITHUB_CLIENT_ID= in =wrangler.toml=.
8282- =npx wrangler secret put GITHUB_CLIENT_SECRET= with the OAuth app's secret, and
83 =GITHUB_TOKEN= with a token of the sponsored account (=read:user=), which renewals use.
83 =GITHUB_TOKEN= with a classic token of an owner of the krazywarez organization (=read:org=,
84 =read:user=), which renewals use to list its sponsors.
8485- =packaging/license-issuer/keygen.sh= set =LICENSE_PRIVATE_KEY= and the app's public key.
8586 Running it again invalidates every key issued so far.
8687
README.org +2 −2
@@ -3,7 +3,7 @@
33#+ATTR_HTML: :alt orgstar on iPad, Mac and iPhone
44[[file:ios/AppStore/header-21x9.png]]
55
6Support orgstar through [[https://github.com/sponsors/ccleberg][GitHub Sponsors]].
6Support orgstar through [[https://github.com/sponsors/krazywarez][GitHub Sponsors]].
77
88orgstar is an editor for [[https://orgmode.org][Org mode]] files on the Mac, iPhone and
99iPad. It reads and writes the same plain-text =.org= files Emacs does, and leaves every
@@ -67,7 +67,7 @@ backlinks; widgets, the Apple Watch app and the clock Live Activity; Calendar an
6767the agenda; and Shortcuts actions.
6868
6969- iPhone and iPad: in-app, $1.99 a month, $19.99 a year or $39.99 once.
70- Mac: by [[https://github.com/sponsors/ccleberg][sponsoring on GitHub]], $60 once for a license key that doesn't expire,
70- Mac: by [[https://github.com/sponsors/krazywarez][sponsoring on GitHub]], $60 once for a license key that doesn't expire,
7171 or $5 a month for a key orgstar renews while you sponsor. Sign in with GitHub at
7272 [[https://krz.sh/apps/orgstar/license][krz.sh/apps/orgstar/license]] for the key and enter it in Settings ▸ orgstar+.
7373
packaging/license-issuer/.dev.vars.example +2 −2
@@ -3,8 +3,8 @@
33# The GitHub OAuth app's client secret. For local runs, use a second OAuth app whose callback
44# URL is http://localhost:8787/license, and override GITHUB_CLIENT_ID here.
55GITHUB_CLIENT_SECRET=
6# A token of the SPONSORABLE account with read:user, for renewals (classic token, or
7# fine-grained with no repository access).
6# A classic token of an owner of the SPONSORABLE organization with read:org and read:user,
7# for renewals: it lists the organization's sponsors, private ones included.
88GITHUB_TOKEN=
99# PKCS#8 PEM from keygen.sh, on one line with \n for line breaks.
1010LICENSE_PRIVATE_KEY=
packaging/license-issuer/worker.js +45 −21
@@ -19,7 +19,7 @@
1919//
2020// Vars (wrangler.toml): SPONSORABLE, LIFETIME_DOLLARS, MONTHLY_DOLLARS, RENEW_DAYS,
2121// GITHUB_CLIENT_ID. Secrets (`wrangler secret put NAME`; locally .dev.vars, see
22// .dev.vars.example): GITHUB_CLIENT_SECRET, GITHUB_TOKEN (SPONSORABLE's token, for renewals),
22// .dev.vars.example): GITHUB_CLIENT_SECRET, GITHUB_TOKEN (an owner of SPONSORABLE, for renewals),
2323// LICENSE_PRIVATE_KEY (PKCS#8 PEM, from keygen.sh).
2424
2525const FEATURES = [
@@ -114,9 +114,11 @@ async function license(request, url, env) {
114114 token,
115115 `query($login: String!) {
116116 viewer { id login }
117 user(login: $login) {
118 sponsorshipForViewerAsSponsor(activeOnly: false) {
119 isActive createdAt tier { monthlyPriceInDollars isOneTime }
117 owner: repositoryOwner(login: $login) {
118 ... on Sponsorable {
119 sponsorshipForViewerAsSponsor(activeOnly: false) {
120 isActive createdAt tier { monthlyPriceInDollars isOneTime }
121 }
120122 }
121123 }
122124 }`,
@@ -125,7 +127,8 @@ async function license(request, url, env) {
125127 if (!data) return page("GitHub can't be reached right now. Try again in a minute.", 502);
126128
127129 const { viewer } = data;
128 const kind = entitlement(data.user?.sponsorshipForViewerAsSponsor, config);
130 const sponsorship = data.owner?.sponsorshipForViewerAsSponsor;
131 const kind = entitlement(sponsorship, config);
129132 const sponsor = `https://github.com/sponsors/${config.sponsorable}`;
130133 const clear = { "set-cookie": `${STATE_COOKIE}=; Path=${url.pathname}; Max-Age=0; HttpOnly; Secure; SameSite=Lax` };
131134 if (!kind)
@@ -139,7 +142,7 @@ async function license(request, url, env) {
139142
140143 const t = "github:" + viewer.id;
141144 const payload = kind === "lifetime"
142 ? { e: viewer.login, t, i: seconds(data.user.sponsorshipForViewerAsSponsor.createdAt) }
145 ? { e: viewer.login, t, i: seconds(sponsorship.createdAt) }
143146 : monthlyPayload(viewer.login, t, config.renewDays);
144147 const key = await sign(payload, env.LICENSE_PRIVATE_KEY);
145148 const note = kind === "lifetime"
@@ -172,21 +175,42 @@ async function renew(request, env) {
172175 const payload = await verify((await request.text()).replace(/\s/g, ""), env.LICENSE_PRIVATE_KEY);
173176 if (!payload?.x || !payload.t?.startsWith("github:")) return text("Not a monthly orgstar+ key.", 400);
174177
175 const data = await graphql(
176 env.GITHUB_TOKEN,
177 `query($id: ID!) {
178 node(id: $id) {
179 ... on User { login sponsorshipForViewerAsSponsorable(activeOnly: true) { isActive tier { monthlyPriceInDollars isOneTime } } }
180 ... on Organization { login sponsorshipForViewerAsSponsorable(activeOnly: true) { isActive tier { monthlyPriceInDollars isOneTime } } }
181 }
182 }`,
183 { id: payload.t.slice("github:".length) },
184 );
185 if (!data) return text("GitHub can't be reached right now.", 502);
186 const node = data.node;
187 if (entitlement(node?.sponsorshipForViewerAsSponsorable, config) !== "monthly")
188 return text("The monthly sponsorship has ended.", 403);
189 return text(await sign(monthlyPayload(node.login, payload.t, config.renewDays), env.LICENSE_PRIVATE_KEY), 200);
178 const found = await activeSponsorship(env.GITHUB_TOKEN, config.sponsorable, payload.t.slice("github:".length));
179 if (found === undefined) return text("GitHub can't be reached right now.", 502);
180 if (entitlement(found, config) !== "monthly") return text("The monthly sponsorship has ended.", 403);
181 return text(await sign(monthlyPayload(found.sponsorEntity.login, payload.t, config.renewDays), env.LICENSE_PRIVATE_KEY), 200);
182}
183
184/// The active sponsorship of `sponsorable` by the account with node ID `id`, from the
185/// sponsorable's own list (private ones too, so `token` belongs to it or an owner of it); null
186/// when there is none, undefined when GitHub can't be reached.
187async function activeSponsorship(token, sponsorable, id) {
188 let after = null;
189 for (;;) {
190 const data = await graphql(
191 token,
192 `query($login: String!, $after: String) {
193 owner: repositoryOwner(login: $login) {
194 ... on Sponsorable {
195 sponsorshipsAsMaintainer(first: 100, after: $after, activeOnly: true, includePrivate: true) {
196 nodes {
197 isActive tier { monthlyPriceInDollars isOneTime }
198 sponsorEntity { ... on User { id login } ... on Organization { id login } }
199 }
200 pageInfo { hasNextPage endCursor }
201 }
202 }
203 }
204 }`,
205 { login: sponsorable, after },
206 );
207 const list = data?.owner?.sponsorshipsAsMaintainer;
208 if (!list) return undefined;
209 const match = list.nodes.find((node) => node.sponsorEntity?.id === id);
210 if (match) return match;
211 if (!list.pageInfo.hasNextPage) return null;
212 after = list.pageInfo.endCursor;
213 }
190214}
191215
192216async function graphql(token, query, variables) {
packaging/license-issuer/worker.test.mjs +14 −8
@@ -67,7 +67,7 @@ async function callback(sponsor, { state = "abc", cookie = "abc" } = {}) {
6767 return withFetch(
6868 (url) => url.includes("access_token")
6969 ? json({ access_token: "visitor-token" })
70 : json({ data: { viewer: { id: "U_1", login: "octo" }, user: { sponsorshipForViewerAsSponsor: sponsor } } }),
70 : json({ data: { viewer: { id: "U_1", login: "octo" }, owner: { sponsorshipForViewerAsSponsor: sponsor } } }),
7171 () => worker.fetch(
7272 new Request(`https://krz.sh/apps/orgstar/license?code=c&state=${state}`, { headers: { cookie: `orgstar_state=${cookie}` } }),
7373 env,
@@ -99,13 +99,19 @@ test("a callback whose state doesn't match the cookie is refused", async () => {
9999 assert.equal((await callback(sponsorship(5), { cookie: "other" })).status, 400);
100100});
101101
102/// …/renew with `key`, GitHub answering `sponsor` for the key's account.
103async function renewal(key, sponsor) {
104 let asked;
102/// …/renew with `key`, GitHub listing the maintainer's sponsors in `pages`, with `sponsor` as
103/// U_1's sponsorship on the last page.
104async function renewal(key, sponsor, pages = 1) {
105 const asked = [];
105106 const response = await withFetch(
106107 (url, init) => {
107 asked = JSON.parse(init.body).variables;
108 return json({ data: { node: { login: "octo-renamed", sponsorshipForViewerAsSponsorable: sponsor } } });
108 const { variables } = JSON.parse(init.body);
109 asked.push(variables);
110 const page = asked.length;
111 const nodes = [{ ...sponsorship(5), sponsorEntity: { id: `U_other${page}`, login: "someone" } }];
112 if (page === pages && sponsor) nodes.push({ ...sponsor, sponsorEntity: { id: "U_1", login: "octo-renamed" } });
113 const pageInfo = { hasNextPage: page < pages, endCursor: `cursor${page}` };
114 return json({ data: { owner: { sponsorshipsAsMaintainer: { nodes, pageInfo } } } });
109115 },
110116 () => worker.fetch(new Request("https://krz.sh/apps/orgstar/renew", { method: "POST", body: key }), env),
111117 );
@@ -114,9 +120,9 @@ async function renewal(key, sponsor) {
114120
115121test("renewal extends a monthly key while the sponsorship is active", async () => {
116122 const old = await sign({ e: "octo", t: "github:U_1", i: 1, x: 2 }, pem);
117 const { response, asked } = await renewal(old, sponsorship(5));
123 const { response, asked } = await renewal(old, sponsorship(5), 2);
118124 assert.equal(response.status, 200);
119 assert.deepEqual(asked, { id: "U_1" });
125 assert.deepEqual(asked, [{ login: "maintainer", after: null }, { login: "maintainer", after: "cursor1" }]);
120126 const fresh = await verify((await response.text()).trim(), pem);
121127 assert.equal(fresh.e, "octo-renamed");
122128 assert.ok(fresh.x > Date.now() / 1000 + 39 * 86400);
packaging/license-issuer/wrangler.toml +1 −1
@@ -8,7 +8,7 @@ routes = [
88]
99
1010[vars]
11SPONSORABLE = "ccleberg"
11SPONSORABLE = "krazywarez"
1212LIFETIME_DOLLARS = "60"
1313MONTHLY_DOLLARS = "5"
1414# A monthly key lasts this long; the app renews it well before.