@magpie-community/opencode-zcode-auth 0.1.49 → 0.1.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +11 -1
  2. package/index.mjs +15 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -294,7 +294,9 @@ and again, all day while the feed names no plan — one GET, nothing
294
294
  posted: ZCode drops plans into the feed on its own schedule (a weekend
295
295
  banner starting at 19:00 Beijing, say), and one that arrives
296
296
  after the day's ask used to sit unclaimed past its short life. The
297
- other answers stand for the day: a claimed plan leaves the feed, so
297
+ other answers stand for the day — but an *ineligible* (code 1004, below)
298
+ is read again in half an hour, as an inactive is: a claimed plan leaves
299
+ the feed, so
298
300
  asking again half an hour later would find nothing and flip the card
299
301
  from "Checked in today" to "No check-in event now"; a captcha plan
300
302
  re-asked makes ZCode demand its captcha again; a done plan re-asked
@@ -313,6 +315,14 @@ the body's code, not the HTTP status:
313
315
  (11-03: seven accounts' ZCODE GLOBAL BUILD all answered 3007). Once
314
316
  claimed there, the gift lands on the account and freeFirst spends it
315
317
  like any other;
318
+ - code 1004 "…not eligible for this plan yet" (HTTP 400): *ineligible*,
319
+ ZCode is not offering this account the plan at that moment. It is read
320
+ again half an hour out, since a plan can be offered later in the day
321
+ (11-04: an account's GLOBAL BUILD banner appeared 28 minutes after it
322
+ signed in). When *every* account answers 1004, check `APP_VERSION`
323
+ first: six accounts all answered 1004 under 3.16.3's header, and four
324
+ of them claimed with code 0 under 3.17.2's, one night, with nothing
325
+ else changed;
316
326
  - anything else, an HTTP error without a code, or a reply that isn't
317
327
  JSON: *failed*, which magpie asks again later that day. It is never
318
328
  taken as claimed, and a failed claim leaves the account's sign-in
package/index.mjs CHANGED
@@ -709,6 +709,12 @@ async function claimHint(s) {
709
709
  // (seen 10-06, #30).
710
710
  const CLAIMED_ALREADY = 1003
711
711
  const CAPTCHA = 3007
712
+ // NOT_ELIGIBLE is /billing/claim's body code for a plan the account is not
713
+ // offered at that moment: HTTP 400 {"code":1004,…}. A stale APP_VERSION
714
+ // answers it for every account at once (11-04: six accounts all answered
715
+ // 1004 under 3.16.3's header, and four of them claimed with code 0 under
716
+ // 3.17.2's, one night, with nothing else changed).
717
+ const NOT_ELIGIBLE = 1004
712
718
  const CAPTCHA_WORDS = /captcha/i
713
719
 
714
720
  // The marketing feed and the claim are gated on the client's version:
@@ -743,6 +749,7 @@ async function claimOne(s, planID) {
743
749
  const msg = typeof env?.msg === "string" ? env.msg : ""
744
750
  if (code === CAPTCHA || CAPTCHA_WORDS.test(msg)) return { outcome: "captcha", why: msg || `code ${code}` }
745
751
  if (code === CLAIMED_ALREADY) return { outcome: "done" }
752
+ if (code === NOT_ELIGIBLE) return { outcome: "ineligible", why: msg || `code ${code}` }
746
753
  if (code === 0 && res.ok) return { outcome: "claimed" }
747
754
  if (!Number.isFinite(code)) return { outcome: "failed", why: `HTTP ${res.status}, unreadable reply ${String(text ?? "").trim().slice(0, 120) || "(empty)"}` }
748
755
  return { outcome: "failed", why: `${msg || "error"} (HTTP ${res.status}, code ${code})` }
@@ -847,7 +854,9 @@ const recheck = () => new Date(Date.now() + RECHECK_MS).toISOString()
847
854
  // toClaim, the app's banners and its preview), as auth.checkin's answer:
848
855
  // inactive when neither lists one, claimed when one was claimed now,
849
856
  // done when each was claimed before, captcha when ZCode wants the app's
850
- // captcha for one (it is claimed in the ZCode app), failed when a list
857
+ // captcha for one (it is claimed in the ZCode app), ineligible when
858
+ // ZCode is not offering one at that moment (code 1004, read again later
859
+ // in the day), failed when a list
851
860
  // or a claim can't be read. A failed one is asked again later in the
852
861
  // day, when a plan claimed now answers 1003. An inactive stands only
853
862
  // until RECHECK_MS from now, so a plan dropped into the feed later in
@@ -867,6 +876,7 @@ async function claimDaily(s) {
867
876
  const said = [
868
877
  claimed.length ? `claimed ${claimed.join(", ")}` : "",
869
878
  ...got.filter((g) => g.outcome === "captcha").map((g) => `${g.name}: claim it in the ZCode app (${g.why})`),
879
+ ...got.filter((g) => g.outcome === "ineligible").map((g) => `${g.name}: ${g.why}`),
870
880
  ...got.filter((g) => g.outcome === "failed").map((g) => `${g.name}: ${g.why}`),
871
881
  ...unread,
872
882
  ].filter(Boolean).join("; ")
@@ -876,6 +886,10 @@ async function claimDaily(s) {
876
886
  if (unread.length || got.some((g) => g.outcome === "failed")) return { outcome: "failed", message: said }
877
887
  if (got.some((g) => g.outcome === "captcha")) return { outcome: "captcha", message: said }
878
888
  if (claimed.length) return { outcome: "claimed", message: said }
889
+ // a plan not offered now can be offered later in the day (11-04: an
890
+ // account's GLOBAL BUILD banner showed 28 minutes after it signed in),
891
+ // so an ineligible is read again half an hour out, as an inactive is
892
+ if (got.some((g) => g.outcome === "ineligible")) return { outcome: "ineligible", message: said, until: recheck() }
879
893
  return { outcome: "done", message: `already claimed: ${named("done").join(", ")}` }
880
894
  }
881
895
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-zcode-auth",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan, and claims its gift plans daily",
5
5
  "type": "module",
6
6
  "main": "./opencode.mjs",