dsh-plugin-subscription-oauth 0.13.0 → 0.16.0
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/lib/auth/provider-controller.d.ts +7 -0
- package/lib/auth/provider-controller.js +1 -0
- package/lib/auth/registry.d.ts +40 -0
- package/lib/auth/registry.js +14 -0
- package/lib/auth/rpc.js +12 -0
- package/lib/auth/workbuddy-flow.d.ts +45 -1
- package/lib/auth/workbuddy-flow.js +222 -2
- package/lib/client/SubscriptionsSection.js +71 -6
- package/lib/client/locales.d.ts +20 -0
- package/lib/client/locales.js +20 -0
- package/lib/client.js +149 -27
- package/lib/client.js.map +1 -1
- package/lib/protocol.d.ts +50 -1
- package/lib/protocol.js +2 -0
- package/lib/providers/workbuddy-credits.d.ts +23 -0
- package/lib/providers/workbuddy-credits.js +52 -0
- package/lib/providers/workbuddy-provider.js +70 -3
- package/lib/providers/workbuddy.d.ts +4 -0
- package/lib/providers/workbuddy.js +14 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -92,6 +92,16 @@ const en = {
|
|
|
92
92
|
modelsAutoChainOff: "Take out of Auto",
|
|
93
93
|
modelsAutoChainEmpty: "No model is enabled, so Auto has nothing to try.",
|
|
94
94
|
autoSwitchLabel: "Offer Auto in the model picker",
|
|
95
|
+
checkinTitle: "Daily check-in",
|
|
96
|
+
checkinPending: "not checked in today",
|
|
97
|
+
checkinDone: "checked in · {days}-day streak",
|
|
98
|
+
checkinClaim: "Check in",
|
|
99
|
+
checkinClaimed: "Checked in, +{credit} credits (streak {days}d)",
|
|
100
|
+
checkinAlready: "Already checked in today (streak {days}d)",
|
|
101
|
+
tasksClaim: "Tasks",
|
|
102
|
+
tasksClaimed: "Claimed {count} task rewards, +{credit} credits",
|
|
103
|
+
tasksClaimable: "{count} tasks ready to claim but not yet earned",
|
|
104
|
+
tasksNone: "No task rewards to claim right now",
|
|
95
105
|
modelsPinned: "pinned",
|
|
96
106
|
usageTitle: "Plan and usage",
|
|
97
107
|
usagePlan: "Plan: {plan}",
|
|
@@ -188,6 +198,16 @@ const zh = {
|
|
|
188
198
|
modelsAutoChainOff: "从自动中移除",
|
|
189
199
|
modelsAutoChainEmpty: "没有启用任何模型,自动没有可尝试的模型。",
|
|
190
200
|
autoSwitchLabel: "在模型选择器中提供 Auto",
|
|
201
|
+
checkinTitle: "每日签到",
|
|
202
|
+
checkinPending: "今日未签到",
|
|
203
|
+
checkinDone: "已签到 · 连签 {days} 天",
|
|
204
|
+
checkinClaim: "签到",
|
|
205
|
+
checkinClaimed: "签到成功,+{credit} 积分(连签 {days} 天)",
|
|
206
|
+
checkinAlready: "今日已签到(连签 {days} 天)",
|
|
207
|
+
tasksClaim: "做任务",
|
|
208
|
+
tasksClaimed: "已领取 {count} 个任务奖励,+{credit} 积分",
|
|
209
|
+
tasksClaimable: "有 {count} 个任务可领但还未达成",
|
|
210
|
+
tasksNone: "现在没有可领的任务奖励",
|
|
191
211
|
modelsPinned: "固定",
|
|
192
212
|
usageTitle: "套餐与额度",
|
|
193
213
|
usagePlan: "套餐:{plan}",
|
|
@@ -1327,38 +1347,64 @@ function windowAmount$1(window$1) {
|
|
|
1327
1347
|
if (window$1.used !== void 0 && window$1.limit !== void 0) return `${String(window$1.used)}/${String(window$1.limit)}`;
|
|
1328
1348
|
return "—";
|
|
1329
1349
|
}
|
|
1330
|
-
/** One account's metered windows, rendered under its account row. */
|
|
1350
|
+
/** One account's metered windows and check-in, rendered under its account row. */
|
|
1331
1351
|
function AccountUsage(props) {
|
|
1332
|
-
const { entry, t } = props;
|
|
1352
|
+
const { entry, t, busyAction, onCheckin, onTasks } = props;
|
|
1333
1353
|
if (entry === void 0) return null;
|
|
1354
|
+
const checkin = entry.checkin;
|
|
1334
1355
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1335
1356
|
style: styles.usageInline,
|
|
1336
|
-
children: [
|
|
1337
|
-
|
|
1338
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1357
|
+
children: [
|
|
1358
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1339
1359
|
style: styles.usageLine,
|
|
1340
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1360
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1341
1361
|
style: styles.modelName,
|
|
1342
|
-
children:
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1362
|
+
children: checkin?.active === true ? checkin.todayCheckedIn ? t("checkinDone", { days: checkin.streakDays }) : t("checkinPending") : ""
|
|
1363
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1364
|
+
style: styles.pushRight,
|
|
1365
|
+
children: [onTasks !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1366
|
+
type: "button",
|
|
1367
|
+
className: "dsh-subscription-quiet",
|
|
1368
|
+
disabled: busyAction,
|
|
1369
|
+
onClick: onTasks,
|
|
1370
|
+
children: t("tasksClaim")
|
|
1371
|
+
}), checkin?.active === true && !checkin.todayCheckedIn && onCheckin !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1372
|
+
type: "button",
|
|
1373
|
+
className: "dsh-subscription-quiet",
|
|
1374
|
+
disabled: busyAction,
|
|
1375
|
+
onClick: onCheckin,
|
|
1376
|
+
children: t("checkinClaim")
|
|
1377
|
+
})]
|
|
1350
1378
|
})]
|
|
1351
|
-
}),
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1379
|
+
}),
|
|
1380
|
+
entry.windows.map((window$1) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1381
|
+
style: styles.usageRow,
|
|
1382
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1383
|
+
style: styles.usageLine,
|
|
1384
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1385
|
+
style: styles.modelName,
|
|
1386
|
+
children: [
|
|
1387
|
+
windowLabel(t, window$1),
|
|
1388
|
+
" · ",
|
|
1389
|
+
windowAmount$1(window$1)
|
|
1390
|
+
]
|
|
1391
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1392
|
+
style: styles.modelMeta,
|
|
1393
|
+
children: window$1.resetsAt === void 0 ? "" : formatReset$1(window$1.resetsAt, t)
|
|
1394
|
+
})]
|
|
1395
|
+
}), window$1.usedPercent !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1396
|
+
className: "dsh-subscription-meter",
|
|
1397
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1398
|
+
style: { width: `${String(Math.min(100, Math.max(0, window$1.usedPercent)))}%` },
|
|
1399
|
+
"data-exhausted": window$1.usedPercent >= 90 ? "true" : "false"
|
|
1400
|
+
})
|
|
1401
|
+
})]
|
|
1402
|
+
}, `${entry.account}-${window$1.label}`)),
|
|
1403
|
+
entry.windows.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1404
|
+
style: styles.statusLine,
|
|
1405
|
+
children: t("usageNone")
|
|
1406
|
+
})
|
|
1407
|
+
]
|
|
1362
1408
|
});
|
|
1363
1409
|
}
|
|
1364
1410
|
/** The pending-login block: a device code, or a link to the sign-in page. */
|
|
@@ -1703,7 +1749,14 @@ function ProviderCard(props) {
|
|
|
1703
1749
|
]
|
|
1704
1750
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountUsage, {
|
|
1705
1751
|
entry: usageEntry,
|
|
1706
|
-
t
|
|
1752
|
+
t,
|
|
1753
|
+
busyAction,
|
|
1754
|
+
...props.onCheckin === void 0 ? {} : { onCheckin: () => {
|
|
1755
|
+
props.onCheckin?.(account.account);
|
|
1756
|
+
} },
|
|
1757
|
+
...props.onTasks === void 0 ? {} : { onTasks: () => {
|
|
1758
|
+
props.onTasks?.(account.account);
|
|
1759
|
+
} }
|
|
1707
1760
|
})]
|
|
1708
1761
|
}, account.account);
|
|
1709
1762
|
}),
|
|
@@ -2112,6 +2165,69 @@ function SubscriptionsSection(props) {
|
|
|
2112
2165
|
refresh,
|
|
2113
2166
|
t
|
|
2114
2167
|
]);
|
|
2168
|
+
/** Claim one account's daily check-in reward, then refresh the figures. */
|
|
2169
|
+
const checkin = (0, react.useCallback)(async (provider, account) => {
|
|
2170
|
+
if (call === void 0) return;
|
|
2171
|
+
setBusyAction(true);
|
|
2172
|
+
try {
|
|
2173
|
+
const result = await call("checkin", {
|
|
2174
|
+
provider,
|
|
2175
|
+
account
|
|
2176
|
+
});
|
|
2177
|
+
if (!mounted.current) return;
|
|
2178
|
+
setMessages((previous) => ({
|
|
2179
|
+
...previous,
|
|
2180
|
+
[provider]: {
|
|
2181
|
+
tone: "success",
|
|
2182
|
+
text: result.already ? t("checkinAlready", { days: result.streakDays }) : t("checkinClaimed", {
|
|
2183
|
+
credit: result.credit,
|
|
2184
|
+
days: result.streakDays
|
|
2185
|
+
})
|
|
2186
|
+
}
|
|
2187
|
+
}));
|
|
2188
|
+
await refresh();
|
|
2189
|
+
} catch (caught) {
|
|
2190
|
+
if (mounted.current) setError(t("actionFailed", { message: messageOf(caught) }));
|
|
2191
|
+
} finally {
|
|
2192
|
+
if (mounted.current) setBusyAction(false);
|
|
2193
|
+
}
|
|
2194
|
+
}, [
|
|
2195
|
+
call,
|
|
2196
|
+
refresh,
|
|
2197
|
+
t
|
|
2198
|
+
]);
|
|
2199
|
+
/** Auto-claim one account's growth-task rewards, then refresh the figures. */
|
|
2200
|
+
const runTasks = (0, react.useCallback)(async (provider, account) => {
|
|
2201
|
+
if (call === void 0) return;
|
|
2202
|
+
setBusyAction(true);
|
|
2203
|
+
try {
|
|
2204
|
+
const result = await call("tasks", {
|
|
2205
|
+
provider,
|
|
2206
|
+
account,
|
|
2207
|
+
claim: true
|
|
2208
|
+
});
|
|
2209
|
+
if (!mounted.current) return;
|
|
2210
|
+
setMessages((previous) => ({
|
|
2211
|
+
...previous,
|
|
2212
|
+
[provider]: {
|
|
2213
|
+
tone: "success",
|
|
2214
|
+
text: result.claimed > 0 ? t("tasksClaimed", {
|
|
2215
|
+
count: result.claimed,
|
|
2216
|
+
credit: result.creditEarned
|
|
2217
|
+
}) : result.claimable > 0 ? t("tasksClaimable", { count: result.claimable }) : t("tasksNone")
|
|
2218
|
+
}
|
|
2219
|
+
}));
|
|
2220
|
+
await refresh();
|
|
2221
|
+
} catch (caught) {
|
|
2222
|
+
if (mounted.current) setError(t("actionFailed", { message: messageOf(caught) }));
|
|
2223
|
+
} finally {
|
|
2224
|
+
if (mounted.current) setBusyAction(false);
|
|
2225
|
+
}
|
|
2226
|
+
}, [
|
|
2227
|
+
call,
|
|
2228
|
+
refresh,
|
|
2229
|
+
t
|
|
2230
|
+
]);
|
|
2115
2231
|
const stopPolling = (0, react.useCallback)(() => {
|
|
2116
2232
|
if (timer.current !== void 0) {
|
|
2117
2233
|
clearInterval(timer.current);
|
|
@@ -2431,7 +2547,13 @@ function SubscriptionsSection(props) {
|
|
|
2431
2547
|
onSetAutoOn: (enabled) => {
|
|
2432
2548
|
setAuto(enabled);
|
|
2433
2549
|
}
|
|
2434
|
-
}
|
|
2550
|
+
},
|
|
2551
|
+
...provider.provider !== "workbuddy" ? {} : { onCheckin: (account) => {
|
|
2552
|
+
checkin(provider.provider, account);
|
|
2553
|
+
} },
|
|
2554
|
+
...provider.provider !== "workbuddy" ? {} : { onTasks: (account) => {
|
|
2555
|
+
runTasks(provider.provider, account);
|
|
2556
|
+
} }
|
|
2435
2557
|
}, provider.provider))
|
|
2436
2558
|
]
|
|
2437
2559
|
});
|