ofsc-utility 1.0.1 → 1.0.3

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/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  export * as OauthTokenService from './oauthTokenService';
2
+ export * as WorkZone from './workZones';
2
3
  export * from './types';
3
4
  export { getOAuthToken } from './oauthTokenService';
4
- declare const StringUtils: {
5
+ export { downloadWorkZoneCSV } from './workZones';
6
+ declare const OfscUtility: {
5
7
  getOAuthToken: any;
8
+ downloadWorkZoneCSV: any;
6
9
  };
7
- export default StringUtils;
10
+ export default OfscUtility;
package/dist/index.js CHANGED
@@ -36,17 +36,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getOAuthToken = exports.OauthTokenService = void 0;
39
+ exports.downloadWorkZoneCSV = exports.getOAuthToken = exports.WorkZone = exports.OauthTokenService = void 0;
40
40
  // Export all methods grouped by category
41
41
  exports.OauthTokenService = __importStar(require("./oauthTokenService"));
42
+ exports.WorkZone = __importStar(require("./workZones"));
42
43
  // Export types
43
44
  __exportStar(require("./types"), exports);
44
45
  // Export individual popular methods for convenience
45
46
  var oauthTokenService_1 = require("./oauthTokenService");
46
47
  Object.defineProperty(exports, "getOAuthToken", { enumerable: true, get: function () { return oauthTokenService_1.getOAuthToken; } });
48
+ var workZones_1 = require("./workZones");
49
+ Object.defineProperty(exports, "downloadWorkZoneCSV", { enumerable: true, get: function () { return workZones_1.downloadWorkZoneCSV; } });
47
50
  // Default export with all functionality
48
- const StringUtils = {
51
+ const OfscUtility = {
49
52
  // Case converters
50
53
  getOAuthToken: require('./oauthTokenService').getOAuthToken,
54
+ downloadWorkZoneCSV: require('./workZones').downloadWorkZoneCSV,
51
55
  };
52
- exports.default = StringUtils;
56
+ exports.default = OfscUtility;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getOAuthToken = getOAuthToken;
4
4
  async function getOAuthToken(clientId, clientSecret, instanceUrl) {
5
5
  const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/oauthTokenService/v2/token`;
6
- const credentials = btoa(`${clientId}:${clientSecret}`);
6
+ const credentials = btoa(`${clientId}@${instanceUrl}:${clientSecret}`);
7
7
  const headers = {
8
8
  'Content-Type': 'application/x-www-form-urlencoded',
9
9
  'Authorization': `Basic ${credentials}`
package/dist/types.d.ts CHANGED
@@ -1,40 +1,13 @@
1
- export interface StringValidationResult {
2
- isValid: boolean;
3
- message?: string;
4
- }
5
- export interface TruncateOptions {
6
- ellipsis?: string;
7
- preserveWords?: boolean;
8
- }
9
- export interface CaseConverter {
10
- toCamelCase: (str: string) => string;
11
- toPascalCase: (str: string) => string;
12
- toSnakeCase: (str: string) => string;
13
- toKebabCase: (str: string) => string;
14
- toTitleCase: (str: string) => string;
15
- }
16
- export interface StringValidator {
17
- isEmail: (str: string) => boolean;
18
- isURL: (str: string) => boolean;
19
- isStrongPassword: (str: string) => StringValidationResult;
20
- isPalindrome: (str: string) => boolean;
21
- hasSpecialChars: (str: string) => boolean;
22
- }
23
- export interface StringTransformer {
24
- reverse: (str: string) => string;
25
- shuffle: (str: string) => string;
26
- slugify: (str: string) => string;
27
- htmlEscape: (str: string) => string;
28
- htmlUnescape: (str: string) => string;
29
- }
30
- export interface StringUtility {
31
- truncate: (str: string, maxLength: number, options?: TruncateOptions) => string;
32
- countWords: (str: string) => number;
33
- countCharacters: (str: string, includeSpaces?: boolean) => number;
34
- extractEmails: (str: string) => string[];
35
- extractNumbers: (str: string) => number[];
36
- generateRandom: (length: number, options?: {
37
- includeNumbers?: boolean;
38
- includeSpecialChars?: boolean;
39
- }) => string;
1
+ export interface WorkZoneItem {
2
+ workZoneLabel: string;
3
+ workZoneName: string;
4
+ status: string;
5
+ travelArea: string;
6
+ keys: string[];
7
+ }
8
+ export interface WorkZoneResponse {
9
+ items: WorkZoneItem[];
10
+ hasMore: boolean;
11
+ offset: number;
12
+ totalResults: number;
40
13
  }
@@ -0,0 +1 @@
1
+ export declare function downloadWorkZoneCSV(clientId: string, clientSecret: string, instanceUrl: string): Promise<void>;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.downloadWorkZoneCSV = downloadWorkZoneCSV;
40
+ const fs = __importStar(require("fs"));
41
+ const node_fetch_1 = __importDefault(require("node-fetch"));
42
+ const index_1 = require("../oauthTokenService/index");
43
+ async function downloadWorkZoneCSV(clientId, clientSecret, instanceUrl) {
44
+ const startTime = Date.now();
45
+ let offset = 0;
46
+ const limit = 100;
47
+ let totalWorkZones = 0;
48
+ let totalKeys = 0;
49
+ let csvRows = [
50
+ "workZoneLabel,workZoneName,key,status,travelArea"
51
+ ];
52
+ while (true) {
53
+ const url = `https://${instanceUrl}.fs.ocs.oraclecloud.com/rest/ofscMetadata/v1/workZones?offset=${offset}&limit=${limit}`;
54
+ let token = await (0, index_1.getOAuthToken)(clientId, clientSecret, instanceUrl);
55
+ const res = await (0, node_fetch_1.default)(url, {
56
+ method: "GET",
57
+ headers: {
58
+ Authorization: `Bearer ${token}`,
59
+ Accept: "application/json"
60
+ }
61
+ });
62
+ if (!res.ok) {
63
+ throw new Error(`Failed to fetch work zones: ${res.status} ${res.statusText}`);
64
+ }
65
+ const data = (await res.json());
66
+ totalWorkZones += data.items.length;
67
+ for (const item of data.items) {
68
+ // Normalize keys (ensure it's always an array)
69
+ const keys = Array.isArray(item.keys)
70
+ ? item.keys
71
+ : item.keys
72
+ ? [item.keys]
73
+ : [];
74
+ totalKeys += keys.length;
75
+ for (const key of keys) {
76
+ csvRows.push(`${item.workZoneLabel},${item.workZoneName},${key},${item.status},${item.travelArea}`);
77
+ }
78
+ }
79
+ if (!data.hasMore)
80
+ break;
81
+ offset = data.offset + limit;
82
+ }
83
+ const csv = csvRows.join("\n");
84
+ const filePath = "./workzones.csv";
85
+ fs.writeFileSync(filePath, csv);
86
+ const endTime = Date.now();
87
+ const durationSec = ((endTime - startTime) / 1000).toFixed(2);
88
+ // --- Summary ---
89
+ console.log("\n=== Work Zone Extraction Summary ===");
90
+ console.log(`Total Work Zones Processed : ${totalWorkZones}`);
91
+ console.log(`Total Keys Extracted : ${totalKeys}`);
92
+ console.log(`CSV Saved To : ${filePath}`);
93
+ console.log(`Time Taken : ${durationSec} sec`);
94
+ console.log("====================================\n");
95
+ console.log("✔ Work Zone CSV download completed.");
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofsc-utility",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A wrapper for Oracle Field Service REST API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,11 +29,15 @@
29
29
  "url": "https://github.com/mailtodanish/ofsc-utility"
30
30
  },
31
31
  "devDependencies": {
32
- "typescript": "^5.0.0",
32
+ "@types/jest": "^29.0.0",
33
33
  "@types/node": "^20.0.0",
34
- "ts-node": "^10.9.0",
34
+ "@types/node-fetch": "^2.6.13",
35
35
  "jest": "^29.0.0",
36
- "@types/jest": "^29.0.0",
37
- "ts-jest": "^29.0.0"
36
+ "ts-jest": "^29.0.0",
37
+ "ts-node": "^10.9.0",
38
+ "typescript": "^5.0.0"
39
+ },
40
+ "dependencies": {
41
+ "node-fetch": "^2.7.0"
38
42
  }
39
- }
43
+ }
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Enhanced ofsc utility
2
2
 
3
- A comprehensive oracle field service utility library with 40+ methods.
3
+ A lightweight utility library for interacting with **Oracle Field Service Cloud (OFSC)**.
4
4
 
5
5
  ## Features
6
6
 
@@ -13,6 +13,43 @@ A comprehensive oracle field service utility library with 40+ methods.
13
13
 
14
14
  ## Installation
15
15
 
16
- ```bash
16
+ ``` bash
17
17
  npm install ofsc-utility
18
- ```
18
+ ```
19
+
20
+ ## Functions implemented
21
+
22
+ ### Download
23
+ downloadWorkZoneCSV(clientId, clientSecret, instanceId)
24
+ getOAuthToken(clientId, clientSecret, instanceId)
25
+
26
+ ## Usage
27
+
28
+ ### CommonJS
29
+
30
+ ``` js
31
+ const ofs = require('ofsc-utility');
32
+
33
+ ofs.getOAuthToken("clientId", "clientSecret", "instanceId")
34
+ .then((token) => {
35
+ console.log(token);
36
+ })
37
+ .catch((err) => {
38
+ console.error("Error fetching token:", err);
39
+ });
40
+ ```
41
+
42
+
43
+ ``` js
44
+ const ofs = require('ofsc-utility');
45
+
46
+ ofs.WorkZone.downloadWorkZoneCSV("clientId", "clientSecret", "instanceId").then((token) => {
47
+ console.log(token);
48
+ });
49
+ ```
50
+
51
+ ## License
52
+
53
+ MIT
54
+
55
+
@@ -1,11 +0,0 @@
1
- /**
2
- * Case conversion utilities
3
- */
4
- export declare function toCamelCase(str: string): string;
5
- export declare function toPascalCase(str: string): string;
6
- export declare function toSnakeCase(str: string): string;
7
- export declare function toKebabCase(str: string): string;
8
- export declare function toTitleCase(str: string): string;
9
- export declare function toSentenceCase(str: string): string;
10
- export declare function toConstantCase(str: string): string;
11
- export declare function toDotCase(str: string): string;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- /**
3
- * Case conversion utilities
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.toCamelCase = toCamelCase;
7
- exports.toPascalCase = toPascalCase;
8
- exports.toSnakeCase = toSnakeCase;
9
- exports.toKebabCase = toKebabCase;
10
- exports.toTitleCase = toTitleCase;
11
- exports.toSentenceCase = toSentenceCase;
12
- exports.toConstantCase = toConstantCase;
13
- exports.toDotCase = toDotCase;
14
- function toCamelCase(str) {
15
- if (!str)
16
- return '';
17
- return str
18
- .replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => index === 0 ? word.toLowerCase() : word.toUpperCase())
19
- .replace(/\s+/g, '')
20
- .replace(/[_-]/g, '');
21
- }
22
- function toPascalCase(str) {
23
- if (!str)
24
- return '';
25
- return str
26
- .replace(/(?:^\w|[A-Z]|\b\w)/g, (word) => word.toUpperCase())
27
- .replace(/\s+/g, '')
28
- .replace(/[_-]/g, '');
29
- }
30
- function toSnakeCase(str) {
31
- if (!str)
32
- return '';
33
- return str
34
- .trim()
35
- .replace(/([a-z])([A-Z])/g, '$1_$2')
36
- .replace(/[\s-]+/g, '_')
37
- .toLowerCase();
38
- }
39
- function toKebabCase(str) {
40
- if (!str)
41
- return '';
42
- return str
43
- .trim()
44
- .replace(/([a-z])([A-Z])/g, '$1-$2')
45
- .replace(/[\s_]+/g, '-')
46
- .toLowerCase();
47
- }
48
- function toTitleCase(str) {
49
- if (!str)
50
- return '';
51
- return str
52
- .toLowerCase()
53
- .split(' ')
54
- .map(word => word.charAt(0).toUpperCase() + word.slice(1))
55
- .join(' ')
56
- .replace(/([a-z])([A-Z])/g, '$1 $2');
57
- }
58
- function toSentenceCase(str) {
59
- if (!str)
60
- return '';
61
- if (str.length === 1)
62
- return str.toUpperCase();
63
- return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
64
- }
65
- function toConstantCase(str) {
66
- return toSnakeCase(str).toUpperCase();
67
- }
68
- function toDotCase(str) {
69
- if (!str)
70
- return '';
71
- return str
72
- .trim()
73
- .replace(/([a-z])([A-Z])/g, '$1.$2')
74
- .replace(/[\s_-]+/g, '.')
75
- .toLowerCase();
76
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * String transformation utilities
3
- */
4
- export declare function reverse(str: string): string;
5
- export declare function shuffle(str: string): string;
6
- export declare function slugify(str: string): string;
7
- export declare function htmlEscape(str: string): string;
8
- export declare function htmlUnescape(str: string): string;
9
- export declare function capitalizeWords(str: string): string;
10
- export declare function replaceAll(str: string, search: string, replacement: string): string;
11
- export declare function removeWhitespace(str: string): string;
12
- export declare function normalizeSpaces(str: string): string;
13
- export declare function toBase64(str: string): string;
14
- export declare function fromBase64(str: string): string;
@@ -1,97 +0,0 @@
1
- "use strict";
2
- /**
3
- * String transformation utilities
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.reverse = reverse;
7
- exports.shuffle = shuffle;
8
- exports.slugify = slugify;
9
- exports.htmlEscape = htmlEscape;
10
- exports.htmlUnescape = htmlUnescape;
11
- exports.capitalizeWords = capitalizeWords;
12
- exports.replaceAll = replaceAll;
13
- exports.removeWhitespace = removeWhitespace;
14
- exports.normalizeSpaces = normalizeSpaces;
15
- exports.toBase64 = toBase64;
16
- exports.fromBase64 = fromBase64;
17
- function reverse(str) {
18
- if (!str)
19
- return '';
20
- return str.split('').reverse().join('');
21
- }
22
- function shuffle(str) {
23
- if (!str)
24
- return '';
25
- const array = str.split('');
26
- for (let i = array.length - 1; i > 0; i--) {
27
- const j = Math.floor(Math.random() * (i + 1));
28
- [array[i], array[j]] = [array[j], array[i]];
29
- }
30
- return array.join('');
31
- }
32
- function slugify(str) {
33
- if (!str)
34
- return '';
35
- return str
36
- .toLowerCase()
37
- .trim()
38
- .replace(/[^\w\s-]/g, '')
39
- .replace(/[\s_-]+/g, '-')
40
- .replace(/^-+|-+$/g, '');
41
- }
42
- function htmlEscape(str) {
43
- if (!str)
44
- return '';
45
- const escapeMap = {
46
- '&': '&amp;',
47
- '<': '&lt;',
48
- '>': '&gt;',
49
- '"': '&quot;',
50
- "'": '&#39;',
51
- '/': '&#x2F;'
52
- };
53
- return str.replace(/[&<>"'/]/g, char => escapeMap[char]);
54
- }
55
- function htmlUnescape(str) {
56
- if (!str)
57
- return '';
58
- const unescapeMap = {
59
- '&amp;': '&',
60
- '&lt;': '<',
61
- '&gt;': '>',
62
- '&quot;': '"',
63
- '&#39;': "'",
64
- '&#x2F;': '/'
65
- };
66
- return str.replace(/&amp;|&lt;|&gt;|&quot;|&#39;|&#x2F;/g, entity => unescapeMap[entity]);
67
- }
68
- function capitalizeWords(str) {
69
- if (!str)
70
- return '';
71
- return str.replace(/\b\w/g, char => char.toUpperCase());
72
- }
73
- function replaceAll(str, search, replacement) {
74
- if (!str)
75
- return '';
76
- return str.split(search).join(replacement);
77
- }
78
- function removeWhitespace(str) {
79
- if (!str)
80
- return '';
81
- return str.replace(/\s+/g, '');
82
- }
83
- function normalizeSpaces(str) {
84
- if (!str)
85
- return '';
86
- return str.replace(/\s+/g, ' ').trim();
87
- }
88
- function toBase64(str) {
89
- if (!str)
90
- return '';
91
- return Buffer.from(str).toString('base64');
92
- }
93
- function fromBase64(str) {
94
- if (!str)
95
- return '';
96
- return Buffer.from(str, 'base64').toString('utf8');
97
- }
@@ -1,14 +0,0 @@
1
- import { StringValidationResult } from '../types';
2
- /**
3
- * String validation utilities
4
- */
5
- export declare function isEmail(str: string): boolean;
6
- export declare function isURL(str: string): boolean;
7
- export declare function isStrongPassword(str: string): StringValidationResult;
8
- export declare function isPalindrome(str: string): boolean;
9
- export declare function hasSpecialChars(str: string): boolean;
10
- export declare function isNumeric(str: string): boolean;
11
- export declare function isAlpha(str: string): boolean;
12
- export declare function isAlphaNumeric(str: string): boolean;
13
- export declare function isEmpty(str: string): boolean;
14
- export declare function isCreditCard(str: string): boolean;
@@ -1,126 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEmail = isEmail;
4
- exports.isURL = isURL;
5
- exports.isStrongPassword = isStrongPassword;
6
- exports.isPalindrome = isPalindrome;
7
- exports.hasSpecialChars = hasSpecialChars;
8
- exports.isNumeric = isNumeric;
9
- exports.isAlpha = isAlpha;
10
- exports.isAlphaNumeric = isAlphaNumeric;
11
- exports.isEmpty = isEmpty;
12
- exports.isCreditCard = isCreditCard;
13
- /**
14
- * String validation utilities
15
- */
16
- function isEmail(str) {
17
- if (!str)
18
- return false;
19
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
20
- return emailRegex.test(str);
21
- }
22
- function isURL(str) {
23
- if (!str)
24
- return false;
25
- try {
26
- const url = new URL(str);
27
- return url.protocol === 'http:' || url.protocol === 'https:';
28
- }
29
- catch {
30
- return false;
31
- }
32
- }
33
- function isStrongPassword(str) {
34
- if (!str) {
35
- return {
36
- isValid: false,
37
- message: 'Password cannot be empty'
38
- };
39
- }
40
- const minLength = 8;
41
- const hasUpperCase = /[A-Z]/.test(str);
42
- const hasLowerCase = /[a-z]/.test(str);
43
- const hasNumbers = /\d/.test(str);
44
- const hasSpecialChars = /[!@#$%^&*(),.?":{}|<>]/.test(str);
45
- if (str.length < minLength) {
46
- return {
47
- isValid: false,
48
- message: `Password must be at least ${minLength} characters long`
49
- };
50
- }
51
- if (!hasUpperCase) {
52
- return {
53
- isValid: false,
54
- message: 'Password must contain at least one uppercase letter'
55
- };
56
- }
57
- if (!hasLowerCase) {
58
- return {
59
- isValid: false,
60
- message: 'Password must contain at least one lowercase letter'
61
- };
62
- }
63
- if (!hasNumbers) {
64
- return {
65
- isValid: false,
66
- message: 'Password must contain at least one number'
67
- };
68
- }
69
- if (!hasSpecialChars) {
70
- return {
71
- isValid: false,
72
- message: 'Password must contain at least one special character'
73
- };
74
- }
75
- return { isValid: true };
76
- }
77
- function isPalindrome(str) {
78
- if (!str)
79
- return true;
80
- const cleanStr = str.toLowerCase().replace(/[^a-z0-9]/g, '');
81
- return cleanStr === cleanStr.split('').reverse().join('');
82
- }
83
- function hasSpecialChars(str) {
84
- if (!str)
85
- return false;
86
- return /[!@#$%^&*(),.?":{}|<>]/.test(str);
87
- }
88
- function isNumeric(str) {
89
- if (!str)
90
- return false;
91
- return /^-?\d*\.?\d+$/.test(str);
92
- }
93
- function isAlpha(str) {
94
- if (!str)
95
- return false;
96
- return /^[A-Za-z]+$/.test(str);
97
- }
98
- function isAlphaNumeric(str) {
99
- if (!str)
100
- return false;
101
- return /^[A-Za-z0-9]+$/.test(str);
102
- }
103
- function isEmpty(str) {
104
- return !str || str.trim().length === 0;
105
- }
106
- function isCreditCard(str) {
107
- if (!str)
108
- return false;
109
- // Simple Luhn algorithm check
110
- const cleanStr = str.replace(/\s+/g, '');
111
- if (!/^\d+$/.test(cleanStr))
112
- return false;
113
- let sum = 0;
114
- let isEven = false;
115
- for (let i = cleanStr.length - 1; i >= 0; i--) {
116
- let digit = parseInt(cleanStr[i], 10);
117
- if (isEven) {
118
- digit *= 2;
119
- if (digit > 9)
120
- digit -= 9;
121
- }
122
- sum += digit;
123
- isEven = !isEven;
124
- }
125
- return sum % 10 === 0;
126
- }