@magpie-community/opencode-zcode-auth 0.1.44 → 0.1.45
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.
- package/README.md +16 -9
- package/index.mjs +29 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -273,12 +273,14 @@ the next read shows it as an ordinary gift bucket.
|
|
|
273
273
|
With ZCode turned on in magpie's Settings → Daily check-in (it is off
|
|
274
274
|
until you turn it on), magpie has the plugin claim each account's gift
|
|
275
275
|
plans once a day (`auth.checkin`; `magpie accounts checkin` asks now). It
|
|
276
|
-
reads
|
|
277
|
-
|
|
276
|
+
reads the banner feed above — the v3.17 client replaced the old preview
|
|
277
|
+
polling with the feed alone, and the feed is gated on the client's
|
|
278
|
+
version, so the plugin asks as the current client (3.17.2) sends — and
|
|
279
|
+
posts each plan the feed offers to
|
|
278
280
|
`POST /api/v1/zcode-plan/billing/claim` (`{"plan_id": …}`) with the
|
|
279
281
|
account's ZCode session, as the app does. An answer of nothing to claim
|
|
280
282
|
carries an `until` half an hour out, so magpie's loop asks again then,
|
|
281
|
-
and again, all day while
|
|
283
|
+
and again, all day while the feed names no plan — one GET, nothing
|
|
282
284
|
posted: ZCode drops plans into the feed on its own schedule (a weekend
|
|
283
285
|
banner starting at 19:00 Beijing, say), and one that arrives
|
|
284
286
|
after the day's ask used to sit unclaimed past its short life. The
|
|
@@ -291,20 +293,25 @@ after one was claimed, is seen the next day. The answer is judged by
|
|
|
291
293
|
the body's code, not the HTTP status:
|
|
292
294
|
|
|
293
295
|
- nothing listed: *inactive* (ZCode answers an account with nothing to
|
|
294
|
-
claim `{"code":0,"msg":""}`, with no list at all). A
|
|
295
|
-
read is *failed*, never nothing to claim
|
|
296
|
-
in neither `billing/preview` nor `billing/current` until its
|
|
297
|
-
`effective_at`, so neither list is read as "claimed or not";
|
|
296
|
+
claim `{"code":0,"msg":""}`, with no list at all). A feed that doesn't
|
|
297
|
+
read is *failed*, never nothing to claim;
|
|
298
298
|
- code 0: *claimed* (the next request uses the plan);
|
|
299
299
|
- code 1003 "target already exists" (HTTP 200): *done*, claimed before;
|
|
300
300
|
- code 3007 "captcha verify failed": *captcha*, the plan is claimed in
|
|
301
|
-
the ZCode app
|
|
302
|
-
|
|
301
|
+
the ZCode app — the claim is gated on the Aliyun captcha the app's
|
|
302
|
+
renderer answers, and a claim from outside the app is refused it
|
|
303
|
+
(11-03: seven accounts' ZCODE GLOBAL BUILD all answered 3007). Once
|
|
304
|
+
claimed there, the gift lands on the account and freeFirst spends it
|
|
305
|
+
like any other;
|
|
303
306
|
- anything else, an HTTP error without a code, or a reply that isn't
|
|
304
307
|
JSON: *failed*, which magpie asks again later that day. It is never
|
|
305
308
|
taken as claimed, and a failed claim leaves the account's sign-in
|
|
306
309
|
alone.
|
|
307
310
|
|
|
311
|
+
The rewards center in the client (奖励中心, the embedded
|
|
312
|
+
`zcode.z.ai/{cn|en}/rewards` page) is the referral program's website,
|
|
313
|
+
separate from these gift plans; its rewards are claimed on that page.
|
|
314
|
+
|
|
308
315
|
An account added with a GLM Coding Plan key has no ZCode session to claim
|
|
309
316
|
with (*ineligible*).
|
|
310
317
|
|
package/index.mjs
CHANGED
|
@@ -644,8 +644,8 @@ async function giftOf(s) {
|
|
|
644
644
|
const CLAIM_HINT = "Gift plans to claim in the ZCode app"
|
|
645
645
|
|
|
646
646
|
// claimHint is the card's line for gift plans ZCode is holding for the
|
|
647
|
-
// account but has not put on it: the app's banners (marketing/touch)
|
|
648
|
-
//
|
|
647
|
+
// account but has not put on it: the app's banners (marketing/touch)
|
|
648
|
+
// list them (toClaim). The
|
|
649
649
|
// card only names them: they are claimed in the ZCode app, or by the
|
|
650
650
|
// daily claim (claimDaily) when the user turned it on; on 10-06 a claim
|
|
651
651
|
// without the app's Aliyun captcha attestation was refused (3007). A window, set aside (it is no
|
|
@@ -678,9 +678,12 @@ const CLAIMED_ALREADY = 1003
|
|
|
678
678
|
const CAPTCHA = 3007
|
|
679
679
|
const CAPTCHA_WORDS = /captcha/i
|
|
680
680
|
|
|
681
|
-
//
|
|
682
|
-
//
|
|
683
|
-
|
|
681
|
+
// The marketing feed and the claim are gated on the client's version:
|
|
682
|
+
// under an older version's header the feed answers empty (11-03: the
|
|
683
|
+
// day's banner showed for 3.17.2 and for no older one), so they go as
|
|
684
|
+
// the current client (3.17.2) sends them.
|
|
685
|
+
const MARKETING_VERSION = "3.17.2"
|
|
686
|
+
const marketingHeaders = () => ({ "X-ZCode-App-Version": MARKETING_VERSION, "X-Platform": platform(), "X-Client-Language": clientLanguage() })
|
|
684
687
|
|
|
685
688
|
// claimOne asks /billing/claim for one plan and says what its body says:
|
|
686
689
|
// "claimed" (code 0), "done" (code 1003, claimed before), "captcha" (the
|
|
@@ -693,7 +696,7 @@ async function claimOne(s, planID) {
|
|
|
693
696
|
try {
|
|
694
697
|
res = await fetch(`${ZCODE}/api/v1/zcode-plan/billing/claim`, {
|
|
695
698
|
method: "POST",
|
|
696
|
-
headers: { "Content-Type": "application/json", Accept: "application/json", "User-Agent": UA, Authorization: "Bearer " + s.jwt, "X-Device-Mid": s.device || anyDevice, ...
|
|
699
|
+
headers: { "Content-Type": "application/json", Accept: "application/json", "User-Agent": UA, Authorization: "Bearer " + s.jwt, "X-Device-Mid": s.device || anyDevice, ...marketingHeaders() },
|
|
697
700
|
body: JSON.stringify({ plan_id: planID }),
|
|
698
701
|
})
|
|
699
702
|
text = await res.text()
|
|
@@ -713,30 +716,17 @@ async function claimOne(s, planID) {
|
|
|
713
716
|
return { outcome: "failed", why: `${msg || "error"} (HTTP ${res.status}, code ${code})` }
|
|
714
717
|
}
|
|
715
718
|
|
|
716
|
-
// previewPlans is /billing/preview's plan list. An account with nothing to
|
|
717
|
-
// claim is answered {"code":0,"msg":"","logid":…}: no data at all, not
|
|
718
|
-
// "plans": [] (the owner's account read 10-30 for hykql's report on
|
|
719
|
-
// Discord; the list is left out when it is empty). call has already judged the code, so a reply
|
|
720
|
-
// without data, or data without plans, is a list of none. Only data that
|
|
721
|
-
// isn't an object, or plans that are there and aren't a list, don't read
|
|
722
|
-
// (null, unknown).
|
|
723
|
-
function previewPlans(d) {
|
|
724
|
-
if (d == null) return []
|
|
725
|
-
if (typeof d !== "object" || Array.isArray(d)) return null
|
|
726
|
-
if (d.plans == null) return []
|
|
727
|
-
return Array.isArray(d.plans) ? d.plans : null
|
|
728
|
-
}
|
|
729
|
-
|
|
730
719
|
// TOUCH is ZCode's marketing feed: the ZCode app's claim banners come
|
|
731
|
-
// from it
|
|
732
|
-
// BUILD", 10-30) is in neither /billing/preview nor /billing/current
|
|
720
|
+
// from it. A banner plan ("ZCODE WEEKEND BUILD", 10-30) is served only
|
|
733
721
|
// while the app shows its banner, and the app claims it through the same
|
|
734
722
|
// /billing/claim (#503's capture of 10-30, kongbai01203: GET
|
|
735
723
|
// /api/v1/marketing/touch?seq=<n, counting up from 0> with the session,
|
|
736
724
|
// X-Device-Mid, X-Client-Language and X-ZCode-App-Version, answered
|
|
737
725
|
// data.deliveries[].banner.buttons[].action = {"type":"claim_zcode_plan",
|
|
738
726
|
// "args":{"plan_id":…}} and the plan's name in
|
|
739
|
-
// banner.background.args.zcode_plan.name).
|
|
727
|
+
// banner.background.args.zcode_plan.name). The v3.17 client reads this
|
|
728
|
+
// feed alone: the old preview polling is gone, and the rewards center's
|
|
729
|
+
// gifts are the rewards website's, claimed in the client.
|
|
740
730
|
const TOUCH = "/api/v1/marketing/touch"
|
|
741
731
|
const CLAIM_ACTION = "claim_zcode_plan"
|
|
742
732
|
let touchSeq = 0
|
|
@@ -775,30 +765,27 @@ function touchPlans(d) {
|
|
|
775
765
|
}
|
|
776
766
|
|
|
777
767
|
// toClaim is every gift plan the account can claim: what the app's
|
|
778
|
-
// marketing feed offers (its banners)
|
|
779
|
-
//
|
|
780
|
-
//
|
|
768
|
+
// marketing feed offers (its banners). The v3.17 client replaced the old
|
|
769
|
+
// preview polling with the feed alone (docs/marketing-touch-client.md in
|
|
770
|
+
// zai-org/ZCode), so the preview is read no more; a rewards center's gift
|
|
771
|
+
// lives on the rewards website, outside this API, and is claimed in the
|
|
772
|
+
// client. unread names a feed that didn't read: its plans are unknown,
|
|
773
|
+
// never none.
|
|
781
774
|
async function toClaim(s) {
|
|
782
775
|
const plans = [], unread = []
|
|
783
776
|
const add = (p) => {
|
|
784
777
|
if (!plans.some((q) => q.plan_id === p.plan_id)) plans.push(p)
|
|
785
778
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
}
|
|
797
|
-
await ask("gift plans to claim", `${ZCODE}${TOUCH}?seq=${touchSeq++}`, { "X-ZCode-App-Version": APP_VERSION, "X-Client-Language": clientLanguage() }, touchPlans)
|
|
798
|
-
await ask("gift plans to claim", `${ZCODE}/api/v1/zcode-plan/billing/preview?app_version=${APP_VERSION}&platform=${platform()}`, zcodeHeaders(), (d) => {
|
|
799
|
-
const l = previewPlans(d)
|
|
800
|
-
return l && l.filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim()).map((p) => ({ plan_id: p.plan_id.trim(), name: first(typeof p.name === "string" ? p.name : "", p.plan_id.trim()) }))
|
|
801
|
-
})
|
|
779
|
+
let d
|
|
780
|
+
try {
|
|
781
|
+
d = await call("GET", `${ZCODE}${TOUCH}?seq=${touchSeq++}`, { auth: "Bearer " + s.jwt, device: s.device, headers: marketingHeaders() })
|
|
782
|
+
} catch (e) {
|
|
783
|
+
unread.push(`gift plans to claim: ${e?.message ?? String(e)}`)
|
|
784
|
+
return { plans, unread }
|
|
785
|
+
}
|
|
786
|
+
const got = touchPlans(d)
|
|
787
|
+
if (!got) unread.push("gift plans to claim: the plan list doesn't read")
|
|
788
|
+
else got.forEach(add)
|
|
802
789
|
return { plans, unread }
|
|
803
790
|
}
|
|
804
791
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magpie-community/opencode-zcode-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
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",
|