@pontix/adapter-duin 0.0.0-stage → 0.1.1
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/LICENSE +661 -0
- package/README.md +98 -2
- package/dist/auth.d.ts +30 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +170 -0
- package/dist/auth.js.map +1 -0
- package/dist/available-plans.d.ts +10 -0
- package/dist/available-plans.d.ts.map +1 -0
- package/dist/available-plans.js +14 -0
- package/dist/available-plans.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/mappers.d.ts +33 -0
- package/dist/mappers.d.ts.map +1 -0
- package/dist/mappers.js +35 -0
- package/dist/mappers.js.map +1 -0
- package/dist/plan-edit.d.ts +79 -0
- package/dist/plan-edit.d.ts.map +1 -0
- package/dist/plan-edit.js +122 -0
- package/dist/plan-edit.js.map +1 -0
- package/dist/session.d.ts +20 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +59 -0
- package/dist/session.js.map +1 -0
- package/dist/shapes.d.ts +626 -0
- package/dist/shapes.d.ts.map +1 -0
- package/dist/shapes.js +219 -0
- package/dist/shapes.js.map +1 -0
- package/dist/tools/add-plan-exercise.d.ts +87 -0
- package/dist/tools/add-plan-exercise.d.ts.map +1 -0
- package/dist/tools/add-plan-exercise.js +47 -0
- package/dist/tools/add-plan-exercise.js.map +1 -0
- package/dist/tools/get-plan.d.ts +29 -0
- package/dist/tools/get-plan.d.ts.map +1 -0
- package/dist/tools/get-plan.js +150 -0
- package/dist/tools/get-plan.js.map +1 -0
- package/dist/tools/list-plans.d.ts +40 -0
- package/dist/tools/list-plans.d.ts.map +1 -0
- package/dist/tools/list-plans.js +110 -0
- package/dist/tools/list-plans.js.map +1 -0
- package/dist/tools/list-workouts.d.ts +73 -0
- package/dist/tools/list-workouts.d.ts.map +1 -0
- package/dist/tools/list-workouts.js +269 -0
- package/dist/tools/list-workouts.js.map +1 -0
- package/dist/tools/remove-plan-exercise.d.ts +23 -0
- package/dist/tools/remove-plan-exercise.d.ts.map +1 -0
- package/dist/tools/remove-plan-exercise.js +33 -0
- package/dist/tools/remove-plan-exercise.js.map +1 -0
- package/dist/tools/search-activities.d.ts +68 -0
- package/dist/tools/search-activities.d.ts.map +1 -0
- package/dist/tools/search-activities.js +136 -0
- package/dist/tools/search-activities.js.map +1 -0
- package/dist/tools/set-plan-exercise-sets.d.ts +79 -0
- package/dist/tools/set-plan-exercise-sets.d.ts.map +1 -0
- package/dist/tools/set-plan-exercise-sets.js +39 -0
- package/dist/tools/set-plan-exercise-sets.js.map +1 -0
- package/mappers.json +197 -0
- package/package.json +45 -3
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { PontixError, upstreamChanged, z } from "@pontix/core/adapter";
|
|
2
|
+
import { fetchAvailablePlans } from "./available-plans.js";
|
|
3
|
+
import { ADAPTER_ID } from "./mappers.js";
|
|
4
|
+
import { findPlanRow, toPlanDetail } from "./tools/get-plan.js";
|
|
5
|
+
/**
|
|
6
|
+
* What the three write tools have in common: they all rewrite one plan.
|
|
7
|
+
*
|
|
8
|
+
* The service has no add, remove or change call. Editing is one
|
|
9
|
+
* `POST /mwa/api/workouts/v1.0/personal-plans/{planId}` that REPLACES the whole
|
|
10
|
+
* plan with the `{ name, exercises[] }` it is given (captured from the app on
|
|
11
|
+
* 2026-11-19), so every change is: read the plan, apply it to the list, send
|
|
12
|
+
* the list back, read the plan again.
|
|
13
|
+
*/
|
|
14
|
+
/** One set as a caller states it: reps with an optional weight, or a duration. */
|
|
15
|
+
const repSet = z
|
|
16
|
+
.object({
|
|
17
|
+
reps: z.number().int().min(1).max(999).describe("Repetitions."),
|
|
18
|
+
weightKg: z.number().min(0).max(1000).optional().describe("Weight in kg. Omit for bodyweight (sent as 0)."),
|
|
19
|
+
})
|
|
20
|
+
.strict();
|
|
21
|
+
const timeSet = z
|
|
22
|
+
.object({
|
|
23
|
+
durationSeconds: z.number().int().min(1).max(86_400).describe("Duration in seconds, for a timed or cardio set."),
|
|
24
|
+
})
|
|
25
|
+
.strict();
|
|
26
|
+
export const setInput = z.union([repSet, timeSet]);
|
|
27
|
+
/** The `sets` argument shared by `add_plan_exercise` and `set_plan_exercise_sets`. */
|
|
28
|
+
export const setsInput = z
|
|
29
|
+
.array(setInput)
|
|
30
|
+
.min(1)
|
|
31
|
+
.max(20)
|
|
32
|
+
.describe("The sets, in order. Each is either { reps, weightKg? } for a strength exercise or { durationSeconds } for a timed one.");
|
|
33
|
+
/**
|
|
34
|
+
* A set as the app sent it for an exercise it had just added: the type and the
|
|
35
|
+
* one or two values, nothing else (the app also sent `pristineSet` and `isDone`
|
|
36
|
+
* flags, which are editor state and are not needed).
|
|
37
|
+
*/
|
|
38
|
+
export function newSet(input) {
|
|
39
|
+
return "durationSeconds" in input
|
|
40
|
+
? { setType: "TIME_BASED", duration: input.durationSeconds }
|
|
41
|
+
: { setType: "REP_BASED", numberOfReps: input.reps, weight: input.weightKg ?? 0 };
|
|
42
|
+
}
|
|
43
|
+
function record(value) {
|
|
44
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
45
|
+
? value
|
|
46
|
+
: undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A set as the service accepts it back.
|
|
50
|
+
*
|
|
51
|
+
* The service reads a strength set without a weight as `weight: null` but
|
|
52
|
+
* refuses to take `null` back (400 `weight-empty`, seen live 2026-11-19); the
|
|
53
|
+
* app sends `0` there, and the service reads that back as `null` again. Every
|
|
54
|
+
* other field goes back as read.
|
|
55
|
+
*/
|
|
56
|
+
function writableSet(raw) {
|
|
57
|
+
const set = record(raw);
|
|
58
|
+
if (set?.["setType"] === "REP_BASED" && set["weight"] === null)
|
|
59
|
+
return { ...set, weight: 0 };
|
|
60
|
+
return raw;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The body that would leave this plan exactly as it is.
|
|
64
|
+
*
|
|
65
|
+
* Built from the raw upstream row, not from the tool's summary, because the
|
|
66
|
+
* summary drops fields (distance, speed, incline, recovery time...) and sending
|
|
67
|
+
* it back would silently erase them. Each exercise is reduced to the three keys
|
|
68
|
+
* the app sent (`id`, `activityId`, `sets`): the rest of a planned exercise is
|
|
69
|
+
* the catalogue activity, notes and equipment, which the service owns. The sets
|
|
70
|
+
* are passed through, null fields included, so what was read is what is
|
|
71
|
+
* written, with one exception the service forces (see `writableSet`); no field
|
|
72
|
+
* this adapter does not understand is dropped.
|
|
73
|
+
*/
|
|
74
|
+
export function bodyFromRow(row) {
|
|
75
|
+
const name = row["name"];
|
|
76
|
+
const planned = row["plannedExercises"];
|
|
77
|
+
if (typeof name !== "string" || !Array.isArray(planned)) {
|
|
78
|
+
throw upstreamChanged(ADAPTER_ID, "A plan", row);
|
|
79
|
+
}
|
|
80
|
+
const exercises = planned.map((raw) => {
|
|
81
|
+
const exercise = record(raw);
|
|
82
|
+
const id = exercise?.["id"];
|
|
83
|
+
const activityId = record(exercise?.["activity"])?.["activityId"];
|
|
84
|
+
const sets = exercise?.["sets"];
|
|
85
|
+
if ((typeof id !== "number" && typeof id !== "string") ||
|
|
86
|
+
id === "" ||
|
|
87
|
+
typeof activityId !== "number" ||
|
|
88
|
+
!Array.isArray(sets)) {
|
|
89
|
+
throw upstreamChanged(ADAPTER_ID, "A planned exercise", raw);
|
|
90
|
+
}
|
|
91
|
+
return { id, activityId, sets: sets.map(writableSet) };
|
|
92
|
+
});
|
|
93
|
+
return { name, exercises };
|
|
94
|
+
}
|
|
95
|
+
/** The error for an exercise id that is not in the plan, before anything is sent. */
|
|
96
|
+
export function unknownExercise(plannedExerciseId, planId) {
|
|
97
|
+
return new PontixError("invalid_input", `Plan ${planId} has no exercise with plannedExerciseId "${plannedExerciseId}". Use duin_get_plan to see its plannedExerciseId values.`, { adapterId: ADAPTER_ID });
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Reads the plan, lets `change` edit the body, sends it and reads the plan back.
|
|
101
|
+
*
|
|
102
|
+
* Refuses before sending anything when the plan is unknown or is not one the
|
|
103
|
+
* member may edit (`editable` must be exactly `true`: null means the service did
|
|
104
|
+
* not say, and a rewrite is not worth a guess). The answer to the POST is an
|
|
105
|
+
* empty `200`, so it goes through `request`, which does not parse the body.
|
|
106
|
+
* The re-read is what the caller sees, so a change the service ignored shows.
|
|
107
|
+
*/
|
|
108
|
+
export async function editPlan(session, planId, change) {
|
|
109
|
+
const before = await fetchAvailablePlans(session);
|
|
110
|
+
const row = findPlanRow(before, planId);
|
|
111
|
+
if (row["editable"] !== true) {
|
|
112
|
+
throw new PontixError("not_supported", `Plan ${planId} cannot be edited: the service does not mark it editable (only your own plans are; a trainer's and the gym's are not). Nothing was changed.`, { adapterId: ADAPTER_ID });
|
|
113
|
+
}
|
|
114
|
+
const body = change(bodyFromRow(row));
|
|
115
|
+
await session.egymHttp.request(`/mwa/api/workouts/v1.0/personal-plans/${encodeURIComponent(planId)}`, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
query: { measurementSystem: "METRIC" },
|
|
118
|
+
body,
|
|
119
|
+
});
|
|
120
|
+
return toPlanDetail(await fetchAvailablePlans(session), planId);
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=plan-edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-edit.js","sourceRoot":"","sources":["../src/plan-edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEhE;;;;;;;;GAQG;AAEH,kFAAkF;AAClF,MAAM,MAAM,GAAG,CAAC;KACb,MAAM,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AAE,iBAAiB,EAAE,QAAQ,EAAE;QACtC,IAAI;KACL,CAAC,CAAC;IACH,OAAO,YAAY,CAAC,MAAM,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuthSession, HttpClient, type AdapterContext, type AdapterSession } from "@pontix/core/adapter";
|
|
2
|
+
import { type DuinToken } from "./auth.js";
|
|
3
|
+
/** What every tool in this connector is handed. */
|
|
4
|
+
export interface DuinSession extends AdapterSession {
|
|
5
|
+
/**
|
|
6
|
+
* NetPulse: the login and the token eGym accepts, and nothing else yet.
|
|
7
|
+
*
|
|
8
|
+
* It carries no `AuthSession`, so a request made through it goes out with no
|
|
9
|
+
* session cookie. NetPulse does serve the member's profile and membership,
|
|
10
|
+
* but a tool reading those would have to carry the cookie itself — which is
|
|
11
|
+
* why they are not listed here as though this client could already fetch them.
|
|
12
|
+
*/
|
|
13
|
+
readonly http: HttpClient;
|
|
14
|
+
/** eGym: catalogue, plans, workouts. Carries the bearer. */
|
|
15
|
+
readonly egymHttp: HttpClient;
|
|
16
|
+
/** For tools that need more than headers, such as `gymLocationId`. */
|
|
17
|
+
readonly auth: AuthSession<DuinToken>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createSession(context: AdapterContext): Promise<DuinSession>;
|
|
20
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAuB3D,mDAAmD;AACnD,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD;;;;;;;OAOG;IACH,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;CACvC;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CA+CjF"}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AuthSession, HttpClient, } from "@pontix/core/adapter";
|
|
2
|
+
import { createAuthFlow } from "./auth.js";
|
|
3
|
+
import { ADAPTER_ID } from "./mappers.js";
|
|
4
|
+
/**
|
|
5
|
+
* The two hosts the service is spread across. The member signs in on the gym
|
|
6
|
+
* chain's own NetPulse host, and the training data then lives on eGym's, which
|
|
7
|
+
* takes a token the first one issues. They are separate overrides because a
|
|
8
|
+
* test stub has to stand in for each independently.
|
|
9
|
+
*/
|
|
10
|
+
const NETPULSE_URL = "https://duetsport.netpulse.com";
|
|
11
|
+
const EGYM_URL = "https://mwa-api.int.api.egym.com";
|
|
12
|
+
/**
|
|
13
|
+
* What NetPulse expects of every request. The capture notes record that the
|
|
14
|
+
* login worked with only these. They are NetPulse's, so eGym does not get them.
|
|
15
|
+
*/
|
|
16
|
+
const NETPULSE_HEADERS = {
|
|
17
|
+
accept: "application/json",
|
|
18
|
+
"x-np-api-version": "1.5",
|
|
19
|
+
"x-np-app-version": "4.1",
|
|
20
|
+
"user-agent": "MyDuetSports/4.1",
|
|
21
|
+
};
|
|
22
|
+
export async function createSession(context) {
|
|
23
|
+
const clientFor = (baseUrl, defaultHeaders, auth) => new HttpClient({
|
|
24
|
+
baseUrl,
|
|
25
|
+
adapterId: ADAPTER_ID,
|
|
26
|
+
limiter: context.limiter,
|
|
27
|
+
logger: context.logger,
|
|
28
|
+
defaultHeaders,
|
|
29
|
+
...(auth === undefined ? {} : { auth }),
|
|
30
|
+
});
|
|
31
|
+
// The NetPulse client carries no session — obtaining a token cannot require
|
|
32
|
+
// one — and only the eGym client gets the `AuthSession`. All the data tools
|
|
33
|
+
// hit eGym, so NetPulse needs no auth once the login is done. Both share one
|
|
34
|
+
// limiter.
|
|
35
|
+
const http = clientFor(context.credentials["baseUrl"] ?? NETPULSE_URL, NETPULSE_HEADERS);
|
|
36
|
+
const auth = new AuthSession(createAuthFlow(http), context, ADAPTER_ID);
|
|
37
|
+
const egymHttp = clientFor(context.credentials["egymBaseUrl"] ?? EGYM_URL, { accept: "application/json" }, auth);
|
|
38
|
+
return {
|
|
39
|
+
http,
|
|
40
|
+
egymHttp,
|
|
41
|
+
auth,
|
|
42
|
+
async healthcheck() {
|
|
43
|
+
// Signing in first, although the request below would do it anyway: asked
|
|
44
|
+
// separately, a refused password is reported as a refused password rather
|
|
45
|
+
// than as an endpoint that failed.
|
|
46
|
+
//
|
|
47
|
+
// Only the opt-ins response goes unread. A tool's shape changing should
|
|
48
|
+
// surface from the tool somebody called, not as a server that will not
|
|
49
|
+
// start — but the login and token shapes are checked here, because a
|
|
50
|
+
// connector that cannot sign in has nothing to offer later either.
|
|
51
|
+
await auth.token();
|
|
52
|
+
await egymHttp.request("/mwa/api/users/v1.0/opt-ins");
|
|
53
|
+
},
|
|
54
|
+
async close() {
|
|
55
|
+
// No persistent connection to release.
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,GAGX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAkB,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,YAAY,GAAG,gCAAgC,CAAC;AACtD,MAAM,QAAQ,GAAG,kCAAkC,CAAC;AAEpD;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