Skip to content

Commit

Permalink
Feature: properties management (#14)
Browse files Browse the repository at this point in the history
* New functions for property management

* Added versioning for OFS testing

* Additional testing
  • Loading branch information
btoron authored Nov 28, 2023
1 parent e13be0e commit c649cee
Show file tree
Hide file tree
Showing 8 changed files with 464 additions and 2,739 deletions.
27 changes: 25 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"name": "@ofs-users/proxy",
"type": "module",
"version": "1.7.2",
"version": "1.8.0",
"description": "A Javascript proxy to access Oracle Field Service via REST API",
"main": "dist/ofs.es.js",
"module": "dist/ofs.es.js",
Expand Down Expand Up @@ -47,6 +47,7 @@
},
"devDependencies": {
"@babel/preset-typescript": "^7.18.6",
"@faker-js/faker": "^8.3.1",
"@jest/globals": "^29.3.1",
"@rollup/plugin-terser": "^0.2.1",
"@rollup/plugin-typescript": "^10.0.1",
Expand All @@ -66,4 +67,4 @@
"dependencies": {
"tslib": "^2.4.1"
}
}
}
69 changes: 69 additions & 0 deletions src/OFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import { PathLike, readFileSync } from "fs";
import {
OFSActivityResponse,
OFSCredentials,
OFSPropertyDetailsResponse,
OFSResponse,
OFSSubscriptionResponse,
OFSPropertyDetails,
OFSPropertyListResponse,
OFSGetPropertiesParams,
} from "./model";

export class OFS {
Expand Down Expand Up @@ -130,6 +134,43 @@ export class OFS {
return fetchPromise;
}

private _put(partialURL: string, requestData: any): Promise<OFSResponse> {
var theURL = new URL(partialURL, this._baseURL);
var myHeaders = new Headers();
myHeaders.append("Authorization", this.authorization);
myHeaders.append("Content-Type", "application/json");
var requestOptions: RequestInit = {
method: "PUT",
headers: myHeaders,
body: JSON.stringify(requestData),
};
const fetchPromise = fetch(theURL, requestOptions)
.then(async function (response) {
// Your code for handling the data you get from the API
if (response.status < 400) {
var data = await response.json();
return new OFSResponse(
theURL,
response.status,
undefined,
data
);
} else {
return new OFSResponse(
theURL,
response.status,
response.statusText,
requestData
);
}
})
.catch((error) => {
console.log("error", error);
return new OFSResponse(theURL, -1);
});
return fetchPromise;
}

private _post(partialURL: string, data: any): Promise<OFSResponse> {
var theURL = new URL(partialURL, this._baseURL);
var myHeaders = new Headers();
Expand Down Expand Up @@ -342,4 +383,32 @@ export class OFS {

return this._postMultiPart(partialURL, formData);
}

//Meta: Property Management

async getProperties(
params: OFSGetPropertiesParams = { offset: 0, limit: 100 }
): Promise<OFSPropertyListResponse> {
const partialURL = "/rest/ofscMetadata/v1/properties";
return this._get(partialURL, params);
}

async getPropertyDetails(pid: string): Promise<OFSPropertyDetailsResponse> {
const partialURL = `/rest/ofscMetadata/v1/properties/${pid}`;
return this._get(partialURL);
}

async createReplaceProperty(
data: OFSPropertyDetails
): Promise<OFSPropertyDetailsResponse> {
const partialURL = `/rest/ofscMetadata/v1/properties/${data.label}`;
return this._put(partialURL, data);
}

async updateProperty(
data: OFSPropertyDetails
): Promise<OFSPropertyDetailsResponse> {
const partialURL = `/rest/ofscMetadata/v1/properties/${data.label}`;
return this._patch(partialURL, data);
}
}
59 changes: 59 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
*/

import { off } from "process";

export type OFSCredentials = {
instance: string;
clientId: string;
Expand Down Expand Up @@ -62,6 +64,47 @@ export interface ActivityListResponse {
links: any;
}

export interface OFSTranslation {
language: string;
name: string;
languageISO: string;
}
export interface OFSPropertyDetails {
label: string;
name?: string;
type?: string;
entity?: string;
gui?: string;
allowDraw?: boolean;
cloneFlag?: boolean;
fileSizeLimit?: string;
getGeolocation?: boolean;
hint?: string;
lines?: number;
maxHeight?: number;
maxWidth?: number;
mimeTypes?: [];
template?: string;
transformation?: any;
watermark?: boolean;
translations?: OFSTranslation[];
links?: any;
}

export interface OFSGetPropertiesParams {
entity?: string;
language?: string;
limit?: number;
offset?: number;
type?: number;
}
class OFSPropertyList {
items: OFSPropertyDetails[] = [];
limit: number = 0;
offset: number = 0;
totalResults: number = 0;
}

export class OFSSubscriptionResponse extends OFSResponse {
data: SubscriptionListResponse = {
totalResults: 0,
Expand All @@ -76,3 +119,19 @@ export class OFSActivityResponse extends OFSResponse {
activityId: 0,
};
}

export class OFSPropertyDetailsResponse extends OFSResponse {
data: OFSPropertyDetails = {
label: "",
name: "",
type: "string",
entity: "activity",
gui: "",
translations: [],
links: undefined,
};
}

export class OFSPropertyListResponse extends OFSResponse {
data: OFSPropertyList = new OFSPropertyList();
}
Loading

0 comments on commit c649cee

Please sign in to comment.