onlinescoutmanager 1.0.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/LICENSE +201 -0
- package/README.md +181 -0
- package/dist/index.cjs +365 -0
- package/dist/index.d.cts +368 -0
- package/dist/index.d.ts +368 -0
- package/dist/index.js +336 -0
- package/package.json +56 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
OSMAuthError: () => OSMAuthError,
|
|
24
|
+
OSMClient: () => OSMClient,
|
|
25
|
+
OSMError: () => OSMError
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/errors.ts
|
|
30
|
+
var OSMError = class extends Error {
|
|
31
|
+
status;
|
|
32
|
+
body;
|
|
33
|
+
constructor(message, status, body) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = "OSMError";
|
|
36
|
+
this.status = status;
|
|
37
|
+
this.body = body;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var OSMAuthError = class extends OSMError {
|
|
41
|
+
constructor(message = "Not authorized \u2014 call client.authorize() first") {
|
|
42
|
+
super(message, 401);
|
|
43
|
+
this.name = "OSMAuthError";
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/resources/attendance.ts
|
|
48
|
+
var AttendanceResource = class {
|
|
49
|
+
constructor(client) {
|
|
50
|
+
this.client = client;
|
|
51
|
+
}
|
|
52
|
+
async get(sectionId, termId, section) {
|
|
53
|
+
return this.client.post(
|
|
54
|
+
"/ext/members/attendance/?action=get",
|
|
55
|
+
{ sectionid: sectionId, termid: termId, section }
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
async getBadgeRequirements(sectionId, section, date) {
|
|
59
|
+
return this.client.post(
|
|
60
|
+
"/ext/members/attendance/?action=getAttendanceBadgeRequirements",
|
|
61
|
+
{ sectionid: sectionId, section, date }
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
async update(params) {
|
|
65
|
+
return this.client.post(
|
|
66
|
+
`/ext/members/attendance/?action=update§ionid=${params.sectionId}&termid=${params.termId}`,
|
|
67
|
+
{
|
|
68
|
+
scouts: JSON.stringify(params.scoutIds),
|
|
69
|
+
selectedDate: params.selectedDate,
|
|
70
|
+
present: params.present,
|
|
71
|
+
section: params.section,
|
|
72
|
+
sectionid: params.sectionId,
|
|
73
|
+
completedBadges: JSON.stringify(params.completedBadges ?? []),
|
|
74
|
+
customData: JSON.stringify(params.customData ?? [])
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/resources/badges.ts
|
|
81
|
+
var BadgesResource = class {
|
|
82
|
+
constructor(client) {
|
|
83
|
+
this.client = client;
|
|
84
|
+
}
|
|
85
|
+
async getTagCloud(sectionId, termId, section) {
|
|
86
|
+
return this.client.post(
|
|
87
|
+
"/ext/programme/clouds/?action=getBadgeTagCloud",
|
|
88
|
+
{ sectionid: sectionId, termid: termId, section }
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/resources/custom-data.ts
|
|
94
|
+
var CustomDataResource = class {
|
|
95
|
+
constructor(client) {
|
|
96
|
+
this.client = client;
|
|
97
|
+
}
|
|
98
|
+
async get(sectionId, memberId) {
|
|
99
|
+
return this.client.post(
|
|
100
|
+
"/ext/customdata/?action=getData",
|
|
101
|
+
{
|
|
102
|
+
section_id: sectionId,
|
|
103
|
+
associated_id: memberId,
|
|
104
|
+
associated_type: "member",
|
|
105
|
+
context: "members",
|
|
106
|
+
group_order: "section"
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
async update(sectionId, memberId, groupId, data) {
|
|
111
|
+
const body = {
|
|
112
|
+
section_id: sectionId,
|
|
113
|
+
associated_id: memberId,
|
|
114
|
+
associated_type: "member",
|
|
115
|
+
group_id: groupId,
|
|
116
|
+
context: "members"
|
|
117
|
+
};
|
|
118
|
+
for (const [key, value] of Object.entries(data)) {
|
|
119
|
+
body[`data[${key}]`] = value;
|
|
120
|
+
}
|
|
121
|
+
return this.client.post(
|
|
122
|
+
"/ext/customdata/?action=update",
|
|
123
|
+
body
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/resources/dashboard.ts
|
|
129
|
+
var DashboardResource = class {
|
|
130
|
+
constructor(client) {
|
|
131
|
+
this.client = client;
|
|
132
|
+
}
|
|
133
|
+
async getNextThings(sectionId, termId, section) {
|
|
134
|
+
return this.client.post(
|
|
135
|
+
"/ext/dashboard/?action=getNextThings",
|
|
136
|
+
{ sectionid: sectionId, termid: termId, section }
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// src/resources/email.ts
|
|
142
|
+
var EmailResource = class {
|
|
143
|
+
constructor(client) {
|
|
144
|
+
this.client = client;
|
|
145
|
+
}
|
|
146
|
+
async getContacts(sectionId) {
|
|
147
|
+
return this.client.post(
|
|
148
|
+
"/ext/members/email/?action=getSelectedEmailsFromContacts",
|
|
149
|
+
{ sectionid: sectionId }
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
async sendTemplate(sectionId, subject, emails, edits) {
|
|
153
|
+
return this.client.post(
|
|
154
|
+
"/ext/members/email/?action=sendTemplate",
|
|
155
|
+
{
|
|
156
|
+
sectionid: sectionId,
|
|
157
|
+
subject,
|
|
158
|
+
emails: JSON.stringify(emails),
|
|
159
|
+
edits: JSON.stringify(edits)
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// src/resources/members.ts
|
|
166
|
+
var MembersResource = class {
|
|
167
|
+
constructor(client) {
|
|
168
|
+
this.client = client;
|
|
169
|
+
}
|
|
170
|
+
async list(sectionId, termId) {
|
|
171
|
+
return this.client.post(
|
|
172
|
+
"/ext/members/contact/?action=getListOfMembers",
|
|
173
|
+
{ sectionid: sectionId, termid: termId }
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
async get(sectionId, scoutId) {
|
|
177
|
+
return this.client.post(
|
|
178
|
+
"/ext/members/contact/?action=getIndividual",
|
|
179
|
+
{
|
|
180
|
+
sectionid: sectionId,
|
|
181
|
+
scoutid: scoutId,
|
|
182
|
+
context: "members"
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
async getTransfers(sectionId) {
|
|
187
|
+
return this.client.post(
|
|
188
|
+
"/ext/members/contact/?action=getMemberTransfers",
|
|
189
|
+
{ sectionid: sectionId }
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
async getPatrols(sectionId, termId) {
|
|
193
|
+
return this.client.post(
|
|
194
|
+
"/ext/members/patrols/?action=getPatrolsWithPeople",
|
|
195
|
+
{ sectionid: sectionId, termid: termId }
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
async getCensus(sectionId, termId) {
|
|
199
|
+
return this.client.post(
|
|
200
|
+
"/ext/members/census/?action=getDetails",
|
|
201
|
+
{ sectionid: sectionId, termid: termId }
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
async getFlexiRecords(sectionId, archived = false) {
|
|
205
|
+
return this.client.post(
|
|
206
|
+
"/ext/members/flexirecords/?action=getPatrolsWithPeople",
|
|
207
|
+
{ sectionid: sectionId, archived: archived ? "y" : "n" }
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
async getDeletable(sectionId) {
|
|
211
|
+
return this.client.get(
|
|
212
|
+
`/v3/members/review/deletion/${sectionId}`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/resources/programme.ts
|
|
218
|
+
var ProgrammeResource = class {
|
|
219
|
+
constructor(client) {
|
|
220
|
+
this.client = client;
|
|
221
|
+
}
|
|
222
|
+
async getSummary(sectionId, termId) {
|
|
223
|
+
return this.client.post(
|
|
224
|
+
"/ext/programme/?action=getProgrammeSummary",
|
|
225
|
+
{ sectionid: sectionId, termid: termId }
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
async getDetails(sectionId, eveningId) {
|
|
229
|
+
return this.client.post(
|
|
230
|
+
"/ext/programme/?action=getProgramme",
|
|
231
|
+
{ sectionid: sectionId, eveningid: eveningId }
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
async getParentRotaMembers(sectionId, eveningId) {
|
|
235
|
+
return this.client.post(
|
|
236
|
+
"/ext/programme/?action=getMembersForParentRota",
|
|
237
|
+
{ sectionid: sectionId, eveningid: eveningId }
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
async getAttachments(sectionId, eveningId) {
|
|
241
|
+
return this.client.post(
|
|
242
|
+
"/ext/programme/?action=programmeAttachmentsManifest",
|
|
243
|
+
{ sectionid: sectionId, eveningid: eveningId }
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
async updateMeeting(sectionId, eveningId, parts) {
|
|
247
|
+
return this.client.post(
|
|
248
|
+
"/ext/programme/?action=editEveningParts",
|
|
249
|
+
{
|
|
250
|
+
sectionid: sectionId,
|
|
251
|
+
eveningid: eveningId,
|
|
252
|
+
parts: JSON.stringify(parts)
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/resources/sections.ts
|
|
259
|
+
var SectionsResource = class {
|
|
260
|
+
constructor(client) {
|
|
261
|
+
this.client = client;
|
|
262
|
+
}
|
|
263
|
+
async list() {
|
|
264
|
+
return this.client.post(
|
|
265
|
+
"/ext/members/sectionplanning/?action=listSections"
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
async getTerms() {
|
|
269
|
+
return this.client.post("/api.php?action=getTerms");
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/client.ts
|
|
274
|
+
var DEFAULT_BASE_URL = "https://www.onlinescoutmanager.co.uk";
|
|
275
|
+
var OSMClient = class {
|
|
276
|
+
apiId;
|
|
277
|
+
token;
|
|
278
|
+
baseUrl;
|
|
279
|
+
auth = null;
|
|
280
|
+
members;
|
|
281
|
+
attendance;
|
|
282
|
+
programme;
|
|
283
|
+
sections;
|
|
284
|
+
badges;
|
|
285
|
+
dashboard;
|
|
286
|
+
customData;
|
|
287
|
+
email;
|
|
288
|
+
constructor(options) {
|
|
289
|
+
this.apiId = options.apiId;
|
|
290
|
+
this.token = options.token;
|
|
291
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
292
|
+
this.members = new MembersResource(this);
|
|
293
|
+
this.attendance = new AttendanceResource(this);
|
|
294
|
+
this.programme = new ProgrammeResource(this);
|
|
295
|
+
this.sections = new SectionsResource(this);
|
|
296
|
+
this.badges = new BadgesResource(this);
|
|
297
|
+
this.dashboard = new DashboardResource(this);
|
|
298
|
+
this.customData = new CustomDataResource(this);
|
|
299
|
+
this.email = new EmailResource(this);
|
|
300
|
+
}
|
|
301
|
+
get isAuthorized() {
|
|
302
|
+
return this.auth !== null;
|
|
303
|
+
}
|
|
304
|
+
async authorize(email, password) {
|
|
305
|
+
const data = await this.post(
|
|
306
|
+
"/users.php?action=authorise",
|
|
307
|
+
{ email, password },
|
|
308
|
+
true
|
|
309
|
+
);
|
|
310
|
+
this.auth = { userid: data.userid, secret: data.secret };
|
|
311
|
+
}
|
|
312
|
+
async post(path, body = {}, skipAuth = false) {
|
|
313
|
+
const params = new URLSearchParams({
|
|
314
|
+
apiid: this.apiId,
|
|
315
|
+
token: this.token,
|
|
316
|
+
...body
|
|
317
|
+
});
|
|
318
|
+
if (!skipAuth) {
|
|
319
|
+
if (!this.auth) throw new OSMAuthError();
|
|
320
|
+
params.set("userid", this.auth.userid);
|
|
321
|
+
params.set("secret", this.auth.secret);
|
|
322
|
+
}
|
|
323
|
+
const url = `${this.baseUrl}${path}`;
|
|
324
|
+
const response = await fetch(url, {
|
|
325
|
+
method: "POST",
|
|
326
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
327
|
+
body: params.toString()
|
|
328
|
+
});
|
|
329
|
+
if (!response.ok) {
|
|
330
|
+
const text = await response.text().catch(() => "");
|
|
331
|
+
throw new OSMError(
|
|
332
|
+
`OSM API error: ${response.status} ${response.statusText}`,
|
|
333
|
+
response.status,
|
|
334
|
+
text
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
return response.json();
|
|
338
|
+
}
|
|
339
|
+
async get(path, query = {}) {
|
|
340
|
+
if (!this.auth) throw new OSMAuthError();
|
|
341
|
+
const params = new URLSearchParams(query);
|
|
342
|
+
const url = `${this.baseUrl}${path}?${params.toString()}`;
|
|
343
|
+
const response = await fetch(url, {
|
|
344
|
+
method: "GET",
|
|
345
|
+
headers: {
|
|
346
|
+
Authorization: `${this.auth.userid}:${this.auth.secret}`
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
if (!response.ok) {
|
|
350
|
+
const text = await response.text().catch(() => "");
|
|
351
|
+
throw new OSMError(
|
|
352
|
+
`OSM API error: ${response.status} ${response.statusText}`,
|
|
353
|
+
response.status,
|
|
354
|
+
text
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
return response.json();
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
361
|
+
0 && (module.exports = {
|
|
362
|
+
OSMAuthError,
|
|
363
|
+
OSMClient,
|
|
364
|
+
OSMError
|
|
365
|
+
});
|