Skip to content

Commit c94e09b

Browse files
committed
init
0 parents  commit c94e09b

File tree

72 files changed

+2264
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2264
-0
lines changed

.eslintignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**/lwc/**/*.css
2+
**/lwc/**/*.html
3+
**/lwc/**/*.json
4+
**/lwc/**/*.svg
5+
**/lwc/**/*.xml
6+
**/aura/**/*.auradoc
7+
**/aura/**/*.cmp
8+
**/aura/**/*.css
9+
**/aura/**/*.design
10+
**/aura/**/*.evt
11+
**/aura/**/*.json
12+
**/aura/**/*.svg
13+
**/aura/**/*.tokens
14+
**/aura/**/*.xml
15+
**/aura/**/*.app
16+
.sfdx

.forceignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# List files or directories below to ignore them when running force:source:push, force:source:pull, and force:source:status
2+
# More information: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_exclude_source.htm
3+
#
4+
5+
package.xml
6+
7+
# LWC configuration files
8+
**/jsconfig.json
9+
**/.eslintrc.json
10+
11+
# LWC Jest
12+
**/__tests__/**

.gitignore

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This file is used for Git repositories to specify intentionally untracked files that Git should ignore.
2+
# If you are not using git, you can delete this file. For more information see: https://git-scm.com/docs/gitignore
3+
# For useful gitignore templates see: https://github.com/github/gitignore
4+
5+
# Salesforce cache
6+
.sf/
7+
.sfdx/
8+
.idea
9+
.localdevserver/
10+
deploy-options.json
11+
12+
# LWC VSCode autocomplete
13+
**/lwc/jsconfig.json
14+
15+
# LWC Jest coverage reports
16+
coverage/
17+
18+
# Logs
19+
logs
20+
*.log
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
# Dependency directories
26+
node_modules/
27+
28+
# Eslint cache
29+
.eslintcache
30+
31+
# MacOS system files
32+
.DS_Store
33+
34+
# Windows system files
35+
Thumbs.db
36+
ehthumbs.db
37+
[Dd]esktop.ini
38+
$RECYCLE.BIN/
39+
40+
# Local environment variables
41+
.env
42+
43+
# Python Salesforce Functions
44+
**/__pycache__/
45+
**/.venv/
46+
**/venv/
47+
48+
# Added by Illuminated Cloud
49+
/IlluminatedCloud/
50+
/out/
51+
target/

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Salesforce DX Project: Next Steps
2+
3+
Now that you’ve created a Salesforce DX project, what’s next? Here are some documentation resources to get you started.
4+
5+
## How Do You Plan to Deploy Your Changes?
6+
7+
Do you want to deploy a set of changes, or create a self-contained application? Choose a [development model](https://developer.salesforce.com/tools/vscode/en/user-guide/development-models).
8+
9+
## Configure Your Salesforce DX Project
10+
11+
The `sfdx-project.json` file contains useful configuration information for your project. See [Salesforce DX Project Configuration](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm) in the _Salesforce DX Developer Guide_ for details about this file.
12+
13+
## Read All About It
14+
15+
- [Salesforce Extensions Documentation](https://developer.salesforce.com/tools/vscode/)
16+
- [Salesforce CLI Setup Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm)
17+
- [Salesforce DX Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_intro.htm)
18+
- [Salesforce CLI Command Reference](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference.htm)

config/project-scratch-def.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"orgName": "integration-util",
3+
"edition": "Developer",
4+
"features": ["EnableSetPasswordInApi"],
5+
"settings": {
6+
"lightningExperienceSettings": {
7+
"enableS1DesktopEnabled": true
8+
},
9+
"mobileSettings": {
10+
"enableS1EncryptedStoragePref2": false
11+
}
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": ["@salesforce/eslint-plugin-aura"],
3+
"extends": ["plugin:@salesforce/eslint-plugin-aura/recommended"],
4+
"rules": {
5+
"vars-on-top": "off",
6+
"no-unused-expressions": "off"
7+
}
8+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public interface HttpServiceInterface {
2+
/**
3+
* Sends a GET request to the specified URL using the provided named credential, path parameters, and query parameters.
4+
*
5+
* @param namedCredential The named credential to use for the request.
6+
* @param pathParam The path parameters to include in the URL, e.g. /{recordId}.
7+
* @param queryParams The query parameters to include in the URL e.g. ?name=value.
8+
* @return The HTTP response received from the server.
9+
*/
10+
HttpResponse GET(String namedCredential,Object pathParam, Map<String,Object> queryParams);
11+
/**
12+
* Sends a POST request to the specified URL using the provided named credential, path parameters, and body.
13+
*
14+
* @param namedCredential The named credential to use for the request.
15+
* @param pathParam The path parameters to include in the URL, e.g. /{recordId}.
16+
* @param body The body object to include in the request.
17+
* @return The HTTP response received from the server.
18+
*/
19+
HttpResponse POST(String namedCredential, Object pathParam,Object body);
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>58.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public interface OAuthClientCredentialsServiceInterface {
2+
/**
3+
* Creates an authorized HTTP request with the provided OAuth token and optional tenant ID.
4+
*
5+
* @param oauthToken The OAuth token to use for authorization.
6+
* @param tenantId The optional tenant ID to include in the request header.
7+
* @return An authorized HttpRequest object.
8+
*/
9+
HttpRequest createAuthorizedRequest(OAuthToken oauthToken,String tenantId);
10+
/**
11+
* Authenticates the client using the provided OAuth client credential.
12+
*
13+
* @param oAuthClientCredential The OAuth client credential used for authentication.
14+
* @return An OAuthToken object representing the authenticated token.
15+
* @throws OAuthException If the authentication fails.
16+
*/
17+
OAuthToken authenticate(OAuthClientCredential oAuthClientCredential);
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>58.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public interface OAuthClientCredentialsStorageInterface {
2+
OAuthToken getToken();
3+
OAuthClientCredential getCredential();
4+
void updateToken(OAuthToken token);
5+
void updateCredential(OAuthClientCredential credential);
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>58.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public interface TestConnectionServiceInterface {
2+
/**
3+
* Tests the connection to a named credential using the provided client credential.
4+
*
5+
* @param obj The object used for authentication, depends on the type of the implementation.
6+
* @param namedCredential The name of the named credential to test the connection with.
7+
* @return A string indicating the success of the connection test.
8+
* @throws OAuthException if the connection fails.
9+
*/
10+
String testConnection(Object obj,String namedCredential);
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>58.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public with sharing class OAuthException extends Exception{
2+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>58.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public with sharing class OAuthTokenException extends Exception{
2+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>58.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public with sharing class IntegrationSecretUtil {
2+
3+
/**
4+
* Masks a given token with a specified mask character.
5+
*
6+
* @example KV0OtVrMBNk8c08 -> KV0*********c08,HxKShF -> H****F, P0dvS5nW -> P0****nW
7+
* @param token the string to be masked.
8+
* @param maskCharacter the character that will be used to mask the token string.
9+
* @return the masked token string or the original token string if the token is null, empty or the token length is less than 3.
10+
* @throws IllegalArgumentException if the replacement string is null or empty.
11+
*/
12+
public String maskToken(String token,String maskCharacter) {
13+
if(String.isBlank(maskCharacter)){
14+
throw new IllegalArgumentException('maskCharacter string cannot be null or empty!');
15+
}
16+
if (String.isBlank(token) || token.length()<=2) {
17+
return token;
18+
}
19+
Integer length = token.length();
20+
Integer visibleChars = Math.max(1, Math.min(3, (length + 1) / 4));
21+
Integer hiddenChars = length - visibleChars * 2;
22+
23+
String hiddenPart = maskCharacter.repeat(hiddenChars);
24+
25+
String serializedToken = token.substring(0, visibleChars) + hiddenPart + token.substring(token.length() - visibleChars);
26+
27+
return serializedToken;
28+
}
29+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>57.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* HttpService implementation for OAuth 2.0 Client Credentials Flow.
3+
*/
4+
public with sharing class OAuthClientCredentialsHttpService implements HttpServiceInterface,TestConnectionServiceInterface{
5+
private final static String CALLOUT = 'callout:';
6+
private final static String HTTP_METHOD_GET = 'GET';
7+
private final static String HTTP_METHOD_POST = 'POST';
8+
9+
private final OAuthClientCredentialsStorageInterface oAuthStorage;
10+
private final OAuthClientCredentialsServiceInterface oAuthService;
11+
12+
public OAuthClientCredentialsHttpService(OAuthClientCredentialsStorageInterface oAuthStorage,
13+
OAuthClientCredentialsServiceInterface oAuthService) {
14+
this.oAuthStorage = oAuthStorage;
15+
this.oAuthService = oAuthService;
16+
}
17+
/**
18+
* Sends a GET request to the specified URL using the provided named credential, path parameters, and query parameters.
19+
*
20+
* @param namedCredential The named credential to use for the request.
21+
* @param pathParam The path parameters to include in the URL, e.g. /{recordId}.
22+
* @param queryParams The query parameters to include in the URL e.g. ?name=value.
23+
* @return The HTTP response received from the server.
24+
*/
25+
public HttpResponse GET(String namedCredential,Object pathParam, Map<String,Object> queryParams) {
26+
String url = ObjectSerializationUtil.serializeURL(namedCredential,pathParam,queryParams);
27+
HttpRequest req = createHttpRequest(HTTP_METHOD_GET, url);
28+
Http http = new Http();
29+
HttpResponse res = http.send(req);
30+
return res;
31+
}
32+
/**
33+
* Sends a POST request to the specified URL using the provided named credential, path parameters, and body.
34+
*
35+
* @param namedCredential The named credential to use for the request.
36+
* @param pathParam The path parameters to include in the URL, e.g. /{recordId}.
37+
* @param body The body object to include in the request.
38+
* @return The HTTP response received from the server.
39+
*/
40+
public HttpResponse POST(String namedCredential, Object pathParam,Object body) {
41+
String url = ObjectSerializationUtil.serializeURL(namedCredential,pathParam,null);
42+
HttpRequest req = createHttpRequest(HTTP_METHOD_POST, url);
43+
if(body!=null){
44+
req.setBody(JSON.serialize(body));
45+
}
46+
Http http = new Http();
47+
HttpResponse res = http.send(req);
48+
return res;
49+
}
50+
/**
51+
* Tests the connection to a named credential using the provided client credential.
52+
*
53+
* @param clientCredential The client credential used for authentication, must be of type OAuthClientCredential.
54+
* @param namedCredential The name of the named credential to test the connection with.
55+
* @return A string indicating the success of the connection test.
56+
* @throws OAuthException If the client credential is not of type OAuthClientCredential or if the connection fails.
57+
*/
58+
public String testConnection(Object clientCredential,String namedCredential) {
59+
ObjectUtil.requireNonNull(clientCredential,'Client Credential cannot be null!');
60+
ObjectUtil.requireNonEmpty(namedCredential,'Named Credential for test connection cannot be empty!');
61+
if(!(clientCredential instanceof OAuthClientCredential)){
62+
throw new OAuthException('Client Credential must be of type OAuthClientCredential!');
63+
}
64+
OAuthClientCredential oAuthClientCredential = (OAuthClientCredential) clientCredential;
65+
66+
OAuthToken oAuthToken = oAuthService.authenticate(oAuthClientCredential);
67+
HttpRequest request = oAuthService.createAuthorizedRequest(oAuthToken,oAuthClientCredential.getTenantId());
68+
69+
request.setEndpoint(CALLOUT+namedCredential);
70+
request.setMethod(HTTP_METHOD_GET);
71+
Http http = new Http();
72+
HttpResponse res = http.send(request);
73+
74+
if(res.getStatusCode() >= 400 && res.getStatusCode() !=404) {
75+
ApiError apiError = ApiError.deserializeJson(res.getBody());
76+
System.debug(LoggingLevel.ERROR,apiError);
77+
throw new OAuthException('Failed to connect! '+apiError);
78+
}
79+
System.debug(LoggingLevel.INFO,'Connection successful for Named Credential: '+namedCredential);
80+
return 'Connection successful!';
81+
}
82+
@TestVisible
83+
private HttpRequest createHttpRequest(String method, String url) {
84+
OAuthClientCredential oAuthClientCredential = oAuthStorage.getCredential();
85+
86+
OAuthToken oAuthToken = getApiToken(oAuthClientCredential);
87+
HttpRequest request = oAuthService.createAuthorizedRequest(oAuthToken,oAuthClientCredential.getTenantId());
88+
89+
request.setEndpoint(url);
90+
request.setMethod(method);
91+
return request;
92+
}
93+
@TestVisible
94+
private OAuthToken getApiToken(OAuthClientCredential oAuthClientCredential){
95+
OAuthToken cachedOAuthToken = oAuthStorage.getToken();
96+
if(!cachedOAuthToken.isExpired()){
97+
return cachedOAuthToken;
98+
}
99+
OAuthToken oAuthToken = oAuthService.authenticate(oAuthClientCredential);
100+
try{
101+
oAuthStorage.updateToken(oAuthToken);
102+
}catch (Exception e){
103+
System.debug(LoggingLevel.ERROR,'Failed to update OAuth token! '+e.getMessage());
104+
}
105+
return oAuthToken;
106+
}
107+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>58.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

0 commit comments

Comments
 (0)