Skip to content

Commit 93bb67f

Browse files
authored
Merge pull request #31 from oracle-samples/feature_extensions
Feature extensions
2 parents de37679 + 1b3b131 commit 93bb67f

File tree

5 files changed

+147
-18
lines changed

5 files changed

+147
-18
lines changed

package-lock.json

Lines changed: 16 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
],
66
"name": "@ofs-users/proxy",
77
"type": "module",
8-
"version": "1.11.0",
8+
"version": "1.13.0",
99
"description": "A Javascript proxy to access Oracle Field Service via REST API",
1010
"main": "dist/ofs.es.js",
1111
"module": "dist/ofs.es.js",

src/OFS.ts

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
OFSPropertyListResponse,
1515
OFSGetPropertiesParams,
1616
OFSTimeslotsResponse,
17+
OFSGetActivitiesParams,
1718
} from "./model";
1819

1920
export * from "./model";
@@ -49,8 +50,8 @@ export class OFS {
4950
public get instance(): string {
5051
return this.credentials.instance || "";
5152
}
52-
public get baseURL(): string {
53-
return this.credentials.baseURL || "";
53+
public get baseURL(): URL {
54+
return this._baseURL || "";
5455
}
5556
private static authenticateUser(credentials: OFSCredentials): string {
5657
if ("token" in credentials && credentials.token != "") {
@@ -347,11 +348,56 @@ export class OFS {
347348
}
348349

349350
// Core: Subscription Management
350-
async getSubscriptions(): Promise<OFSSubscriptionResponse> {
351+
async getSubscriptions(
352+
all: boolean = false
353+
): Promise<OFSSubscriptionResponse> {
351354
const partialURL = "/rest/ofscCore/v1/events/subscriptions";
355+
return this._get(partialURL, { allSubscriptions: all });
356+
}
357+
358+
async createSubscription(data: any): Promise<OFSResponse> {
359+
const partialURL = "/rest/ofscCore/v1/events/subscriptions/";
360+
return this._post(partialURL, data);
361+
}
362+
363+
async deleteSubscription(sid: string): Promise<OFSResponse> {
364+
const partialURL = `/rest/ofscCore/v1/events/subscriptions/${sid}`;
365+
return this._delete(partialURL);
366+
}
367+
368+
async getSubscriptionDetails(sid: string): Promise<OFSResponse> {
369+
const partialURL = `/rest/ofscCore/v1/events/subscriptions/${sid}`;
352370
return this._get(partialURL);
353371
}
354372

373+
// Core: Event Management
374+
async getEvents(
375+
sid: string,
376+
page: string = "lastRequested",
377+
since = null,
378+
limit: number = 1000
379+
): Promise<OFSResponse> {
380+
var params: {
381+
subscriptionId: string;
382+
page?: string;
383+
limit: number;
384+
since?: string | null;
385+
} = {
386+
subscriptionId: sid,
387+
page: page,
388+
limit: limit,
389+
since: since,
390+
};
391+
if (since == null) {
392+
delete params.since;
393+
} else {
394+
delete params.page;
395+
}
396+
397+
const partialURL = "/rest/ofscCore/v1/events";
398+
return this._get(partialURL, params);
399+
}
400+
355401
// Core: Activity Management
356402
async createActivity(data: any): Promise<OFSResponse> {
357403
const partialURL = "/rest/ofscCore/v1/activities";
@@ -521,6 +567,20 @@ export class OFS {
521567
return this._get(partialURL);
522568
}
523569

570+
// Core: Activities Management
571+
async getActivities(
572+
params: OFSGetActivitiesParams,
573+
offset: number = 0,
574+
limit: number = 100
575+
): Promise<OFSResponse> {
576+
const partialURL = "/rest/ofscCore/v1/activities";
577+
return this._get(partialURL, {
578+
...params,
579+
offset: offset,
580+
limit: limit,
581+
});
582+
}
583+
524584
// Metadata: Plugin Management
525585
async importPlugins(file?: PathLike, data?: string): Promise<OFSResponse> {
526586
const partialURL =

src/model.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,13 @@ export class OFSPropertyListResponse extends OFSResponse {
163163
export class OFSTimeslotsResponse extends OFSResponse {
164164
data: OFSTimeslotsList = new OFSTimeslotsList();
165165
}
166+
167+
export interface OFSGetActivitiesParams {
168+
resources: string;
169+
dateFrom?: string;
170+
dateTo?: string;
171+
fields?: string;
172+
includeChildren?: string;
173+
includeNonScheduled?: boolean;
174+
q?: string;
175+
}

test/general/core.activities.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,60 @@ test("Get File Property (Full Binary)", async () => {
277277
throw error;
278278
}
279279
});
280+
281+
test("Get Activities", async () => {
282+
var result = await myProxy.getActivities(
283+
{
284+
resources: "SUNRISE",
285+
dateFrom: "2025-02-01",
286+
dateTo: "2025-03-02",
287+
},
288+
0,
289+
100
290+
);
291+
if (result.status !== 200) {
292+
console.log(result);
293+
}
294+
expect(result.status).toBe(200);
295+
expect(result.data.items.length).toBeGreaterThan(0);
296+
expect(result.data.items[0].activityId).toBeGreaterThan(0);
297+
});
298+
299+
test("Get Activities with includeChildren", async () => {
300+
var result = await myProxy.getActivities(
301+
{
302+
resources: "SUNRISE",
303+
dateFrom: "2025-02-01",
304+
dateTo: "2025-03-02",
305+
includeChildren: "all",
306+
},
307+
0,
308+
100
309+
);
310+
if (result.status !== 200) {
311+
console.log(result);
312+
}
313+
expect(result.status).toBe(200);
314+
expect(result.data.items.length).toBeGreaterThan(0);
315+
expect(result.data.items[0].activityId).toBeGreaterThan(0);
316+
});
317+
318+
test("Get Activities with all the parameters", async () => {
319+
var result = await myProxy.getActivities(
320+
{
321+
resources: "SUNRISE",
322+
dateFrom: "2025-02-01",
323+
dateTo: "2025-03-02",
324+
includeChildren: "all",
325+
includeNonScheduled: true,
326+
},
327+
0,
328+
100
329+
);
330+
if (result.status !== 200) {
331+
console.log(result);
332+
}
333+
expect(result.status).toBe(200);
334+
expect(result.data.items.length).toBeGreaterThan(0);
335+
expect(result.data.items[0].activityId).toBeGreaterThan(0);
336+
});

0 commit comments

Comments
 (0)