ofsc-utility 1.0.1 → 1.0.2
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 +2 -2
- package/dist/index.js +2 -2
- package/dist/oauthTokenService/index.js +1 -1
- package/dist/types.d.ts +0 -36
- package/package.json +1 -1
- package/readme.md +27 -3
- package/dist/case-converters/index.d.ts +0 -11
- package/dist/case-converters/index.js +0 -76
- package/dist/transformers/index.d.ts +0 -14
- package/dist/transformers/index.js +0 -97
- package/dist/validators/index.d.ts +0 -14
- package/dist/validators/index.js +0 -126
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * as OauthTokenService from './oauthTokenService';
|
|
2
2
|
export * from './types';
|
|
3
3
|
export { getOAuthToken } from './oauthTokenService';
|
|
4
|
-
declare const
|
|
4
|
+
declare const OfscUtility: {
|
|
5
5
|
getOAuthToken: any;
|
|
6
6
|
};
|
|
7
|
-
export default
|
|
7
|
+
export default OfscUtility;
|
package/dist/index.js
CHANGED
|
@@ -45,8 +45,8 @@ __exportStar(require("./types"), exports);
|
|
|
45
45
|
var oauthTokenService_1 = require("./oauthTokenService");
|
|
46
46
|
Object.defineProperty(exports, "getOAuthToken", { enumerable: true, get: function () { return oauthTokenService_1.getOAuthToken; } });
|
|
47
47
|
// Default export with all functionality
|
|
48
|
-
const
|
|
48
|
+
const OfscUtility = {
|
|
49
49
|
// Case converters
|
|
50
50
|
getOAuthToken: require('./oauthTokenService').getOAuthToken,
|
|
51
51
|
};
|
|
52
|
-
exports.default =
|
|
52
|
+
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
|
@@ -2,39 +2,3 @@ export interface StringValidationResult {
|
|
|
2
2
|
isValid: boolean;
|
|
3
3
|
message?: string;
|
|
4
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;
|
|
40
|
-
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Enhanced ofsc utility
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A lightweight utility library for interacting with **Oracle Field Service Cloud (OFSC)**.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -13,6 +13,30 @@ 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
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### CommonJS
|
|
23
|
+
|
|
24
|
+
``` js
|
|
25
|
+
const ofs = require('ofsc-utility');
|
|
26
|
+
|
|
27
|
+
ofs.getOAuthToken("clientId", "clientSecret", "instanceId")
|
|
28
|
+
.then((token) => {
|
|
29
|
+
console.log(token);
|
|
30
|
+
})
|
|
31
|
+
.catch((err) => {
|
|
32
|
+
console.error("Error fetching token:", err);
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Parameters
|
|
37
|
+
|
|
38
|
+
Parameter Type Description
|
|
39
|
+
-------------- -------- ------------------------------
|
|
40
|
+
clientId string OFSC OAuth client ID
|
|
41
|
+
clientSecret string OFSC OAuth client secret
|
|
42
|
+
instanceId string OFSC environment/instance ID
|
|
@@ -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
|
-
'&': '&',
|
|
47
|
-
'<': '<',
|
|
48
|
-
'>': '>',
|
|
49
|
-
'"': '"',
|
|
50
|
-
"'": ''',
|
|
51
|
-
'/': '/'
|
|
52
|
-
};
|
|
53
|
-
return str.replace(/[&<>"'/]/g, char => escapeMap[char]);
|
|
54
|
-
}
|
|
55
|
-
function htmlUnescape(str) {
|
|
56
|
-
if (!str)
|
|
57
|
-
return '';
|
|
58
|
-
const unescapeMap = {
|
|
59
|
-
'&': '&',
|
|
60
|
-
'<': '<',
|
|
61
|
-
'>': '>',
|
|
62
|
-
'"': '"',
|
|
63
|
-
''': "'",
|
|
64
|
-
'/': '/'
|
|
65
|
-
};
|
|
66
|
-
return str.replace(/&|<|>|"|'|//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;
|
package/dist/validators/index.js
DELETED
|
@@ -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
|
-
}
|