Skip to content

Commit c649cee

Browse files
authored
Feature: properties management (#14)
* New functions for property management * Added versioning for OFS testing * Additional testing
1 parent e13be0e commit c649cee

File tree

8 files changed

+464
-2739
lines changed

8 files changed

+464
-2739
lines changed

package-lock.json

+25-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
],
66
"name": "@ofs-users/proxy",
77
"type": "module",
8-
"version": "1.7.2",
8+
"version": "1.8.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",
@@ -47,6 +47,7 @@
4747
},
4848
"devDependencies": {
4949
"@babel/preset-typescript": "^7.18.6",
50+
"@faker-js/faker": "^8.3.1",
5051
"@jest/globals": "^29.3.1",
5152
"@rollup/plugin-terser": "^0.2.1",
5253
"@rollup/plugin-typescript": "^10.0.1",
@@ -66,4 +67,4 @@
6667
"dependencies": {
6768
"tslib": "^2.4.1"
6869
}
69-
}
70+
}

src/OFS.ts

+69
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import { PathLike, readFileSync } from "fs";
77
import {
88
OFSActivityResponse,
99
OFSCredentials,
10+
OFSPropertyDetailsResponse,
1011
OFSResponse,
1112
OFSSubscriptionResponse,
13+
OFSPropertyDetails,
14+
OFSPropertyListResponse,
15+
OFSGetPropertiesParams,
1216
} from "./model";
1317

1418
export class OFS {
@@ -130,6 +134,43 @@ export class OFS {
130134
return fetchPromise;
131135
}
132136

137+
private _put(partialURL: string, requestData: any): Promise<OFSResponse> {
138+
var theURL = new URL(partialURL, this._baseURL);
139+
var myHeaders = new Headers();
140+
myHeaders.append("Authorization", this.authorization);
141+
myHeaders.append("Content-Type", "application/json");
142+
var requestOptions: RequestInit = {
143+
method: "PUT",
144+
headers: myHeaders,
145+
body: JSON.stringify(requestData),
146+
};
147+
const fetchPromise = fetch(theURL, requestOptions)
148+
.then(async function (response) {
149+
// Your code for handling the data you get from the API
150+
if (response.status < 400) {
151+
var data = await response.json();
152+
return new OFSResponse(
153+
theURL,
154+
response.status,
155+
undefined,
156+
data
157+
);
158+
} else {
159+
return new OFSResponse(
160+
theURL,
161+
response.status,
162+
response.statusText,
163+
requestData
164+
);
165+
}
166+
})
167+
.catch((error) => {
168+
console.log("error", error);
169+
return new OFSResponse(theURL, -1);
170+
});
171+
return fetchPromise;
172+
}
173+
133174
private _post(partialURL: string, data: any): Promise<OFSResponse> {
134175
var theURL = new URL(partialURL, this._baseURL);
135176
var myHeaders = new Headers();
@@ -342,4 +383,32 @@ export class OFS {
342383

343384
return this._postMultiPart(partialURL, formData);
344385
}
386+
387+
//Meta: Property Management
388+
389+
async getProperties(
390+
params: OFSGetPropertiesParams = { offset: 0, limit: 100 }
391+
): Promise<OFSPropertyListResponse> {
392+
const partialURL = "/rest/ofscMetadata/v1/properties";
393+
return this._get(partialURL, params);
394+
}
395+
396+
async getPropertyDetails(pid: string): Promise<OFSPropertyDetailsResponse> {
397+
const partialURL = `/rest/ofscMetadata/v1/properties/${pid}`;
398+
return this._get(partialURL);
399+
}
400+
401+
async createReplaceProperty(
402+
data: OFSPropertyDetails
403+
): Promise<OFSPropertyDetailsResponse> {
404+
const partialURL = `/rest/ofscMetadata/v1/properties/${data.label}`;
405+
return this._put(partialURL, data);
406+
}
407+
408+
async updateProperty(
409+
data: OFSPropertyDetails
410+
): Promise<OFSPropertyDetailsResponse> {
411+
const partialURL = `/rest/ofscMetadata/v1/properties/${data.label}`;
412+
return this._patch(partialURL, data);
413+
}
345414
}

src/model.ts

+59
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
44
*/
55

6+
import { off } from "process";
7+
68
export type OFSCredentials = {
79
instance: string;
810
clientId: string;
@@ -62,6 +64,47 @@ export interface ActivityListResponse {
6264
links: any;
6365
}
6466

67+
export interface OFSTranslation {
68+
language: string;
69+
name: string;
70+
languageISO: string;
71+
}
72+
export interface OFSPropertyDetails {
73+
label: string;
74+
name?: string;
75+
type?: string;
76+
entity?: string;
77+
gui?: string;
78+
allowDraw?: boolean;
79+
cloneFlag?: boolean;
80+
fileSizeLimit?: string;
81+
getGeolocation?: boolean;
82+
hint?: string;
83+
lines?: number;
84+
maxHeight?: number;
85+
maxWidth?: number;
86+
mimeTypes?: [];
87+
template?: string;
88+
transformation?: any;
89+
watermark?: boolean;
90+
translations?: OFSTranslation[];
91+
links?: any;
92+
}
93+
94+
export interface OFSGetPropertiesParams {
95+
entity?: string;
96+
language?: string;
97+
limit?: number;
98+
offset?: number;
99+
type?: number;
100+
}
101+
class OFSPropertyList {
102+
items: OFSPropertyDetails[] = [];
103+
limit: number = 0;
104+
offset: number = 0;
105+
totalResults: number = 0;
106+
}
107+
65108
export class OFSSubscriptionResponse extends OFSResponse {
66109
data: SubscriptionListResponse = {
67110
totalResults: 0,
@@ -76,3 +119,19 @@ export class OFSActivityResponse extends OFSResponse {
76119
activityId: 0,
77120
};
78121
}
122+
123+
export class OFSPropertyDetailsResponse extends OFSResponse {
124+
data: OFSPropertyDetails = {
125+
label: "",
126+
name: "",
127+
type: "string",
128+
entity: "activity",
129+
gui: "",
130+
translations: [],
131+
links: undefined,
132+
};
133+
}
134+
135+
export class OFSPropertyListResponse extends OFSResponse {
136+
data: OFSPropertyList = new OFSPropertyList();
137+
}

0 commit comments

Comments
 (0)