sfq 0.0.29__py3-none-any.whl → 0.0.31__py3-none-any.whl

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.
sfq/__init__.py CHANGED
@@ -10,6 +10,7 @@ import os
10
10
  import re
11
11
  import time
12
12
  import warnings
13
+ import webbrowser
13
14
  import xml.etree.ElementTree as ET
14
15
  from collections import OrderedDict
15
16
  from concurrent.futures import ThreadPoolExecutor, as_completed
@@ -99,7 +100,7 @@ class SFAuth:
99
100
  access_token: Optional[str] = None,
100
101
  token_expiration_time: Optional[float] = None,
101
102
  token_lifetime: int = 15 * 60,
102
- user_agent: str = "sfq/0.0.29",
103
+ user_agent: str = "sfq/0.0.31",
103
104
  sforce_client: str = "_auto",
104
105
  proxy: str = "_auto",
105
106
  ) -> None:
@@ -997,9 +998,10 @@ class SFAuth:
997
998
 
998
999
  return combined_response or None
999
1000
 
1000
- def _gen_soap_envelope(self, header: str, body: str) -> str:
1001
- """Generates a full SOAP envelope with all required namespaces for Salesforce Enterprise API."""
1002
- return (
1001
+ def _gen_soap_envelope(self, header: str, body: str, type: str) -> str:
1002
+ """Generates a full SOAP envelope with all required namespaces for Salesforce API."""
1003
+ if type == "enterprise":
1004
+ return (
1003
1005
  '<?xml version="1.0" encoding="UTF-8"?>'
1004
1006
  "<soapenv:Envelope "
1005
1007
  'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" '
@@ -1010,8 +1012,24 @@ class SFAuth:
1010
1012
  f"{header}{body}"
1011
1013
  "</soapenv:Envelope>"
1012
1014
  )
1015
+ elif type == "tooling":
1016
+ return (
1017
+ '<?xml version="1.0" encoding="UTF-8"?>'
1018
+ "<soapenv:Envelope "
1019
+ 'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" '
1020
+ 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
1021
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
1022
+ 'xmlns="urn:tooling.soap.sforce.com" '
1023
+ 'xmlns:mns="urn:metadata.tooling.soap.sforce.com" '
1024
+ 'xmlns:sf="urn:sobject.tooling.soap.sforce.com">'
1025
+ f"{header}{body}"
1026
+ "</soapenv:Envelope>"
1027
+ )
1028
+ raise ValueError(
1029
+ f"Unsupported API type: {type}. Must be 'enterprise' or 'tooling'."
1030
+ )
1013
1031
 
1014
- def _gen_soap_header(self):
1032
+ def _gen_soap_header(self) -> str:
1015
1033
  """This function generates the header for the SOAP request."""
1016
1034
  headers = self._get_common_headers()
1017
1035
  session_id = headers["Authorization"].split(" ")[1]
@@ -1099,6 +1117,7 @@ class SFAuth:
1099
1117
  insert_list: List[Dict[str, Any]],
1100
1118
  batch_size: int = 200,
1101
1119
  max_workers: int = None,
1120
+ api_type: Literal["enterprise", "tooling"] = "enterprise",
1102
1121
  ) -> Optional[Dict[str, Any]]:
1103
1122
  """
1104
1123
  Execute the Insert API to insert multiple records via SOAP calls.
@@ -1110,7 +1129,18 @@ class SFAuth:
1110
1129
  :return: JSON response from the insert request or None on failure.
1111
1130
  """
1112
1131
 
1113
- endpoint = f"/services/Soap/c/{self.api_version}"
1132
+ endpoint = "/services/Soap/"
1133
+ if api_type == "enterprise":
1134
+ endpoint += f"c/{self.api_version}"
1135
+ elif api_type == "tooling":
1136
+ endpoint += f"T/{self.api_version}"
1137
+ else:
1138
+ logger.error(
1139
+ "Invalid API type: %s. Must be one of: 'enterprise', 'tooling'.",
1140
+ api_type,
1141
+ )
1142
+ return None
1143
+ endpoint = endpoint.replace('/v', '/') # handle API versioning in the endpoint
1114
1144
 
1115
1145
  if isinstance(insert_list, dict):
1116
1146
  insert_list = [insert_list]
@@ -1123,7 +1153,7 @@ class SFAuth:
1123
1153
  def insert_chunk(chunk: List[Dict[str, Any]]) -> Optional[Dict[str, Any]]:
1124
1154
  header = self._gen_soap_header()
1125
1155
  body = self._gen_soap_body(sobject=sobject, method="create", data=chunk)
1126
- envelope = self._gen_soap_envelope(header, body)
1156
+ envelope = self._gen_soap_envelope(header=header, body=body, type=api_type)
1127
1157
  soap_headers = self._get_common_headers().copy()
1128
1158
  soap_headers["Content-Type"] = "text/xml; charset=UTF-8"
1129
1159
  soap_headers["SOAPAction"] = '""'
@@ -1165,3 +1195,33 @@ class SFAuth:
1165
1195
  ]
1166
1196
 
1167
1197
  return combined_response or None
1198
+
1199
+ def _debug_cleanup_apex_logs(self):
1200
+ """
1201
+ This function performs cleanup operations for Apex debug logs.
1202
+ """
1203
+ apex_logs = self.query("SELECT Id FROM ApexLog ORDER BY LogLength DESC")
1204
+ if apex_logs and apex_logs.get("records"):
1205
+ log_ids = [log["Id"] for log in apex_logs["records"]]
1206
+ if log_ids:
1207
+ delete_response = self.cdelete(log_ids)
1208
+ logger.debug("Deleted Apex logs: %s", delete_response)
1209
+ else:
1210
+ logger.debug("No Apex logs found to delete.")
1211
+
1212
+ def debug_cleanup(self, apex_logs: bool = True) -> None:
1213
+ """
1214
+ Perform cleanup operations for Apex debug logs.
1215
+ """
1216
+ if apex_logs:
1217
+ self._debug_cleanup_apex_logs()
1218
+
1219
+ def open_frontdoor(self) -> None:
1220
+ """
1221
+ This function opens the Salesforce Frontdoor URL in the default web browser.
1222
+ """
1223
+ if not self.access_token:
1224
+ self._get_common_headers()
1225
+ sid = quote(self.access_token, safe="")
1226
+ frontdoor_url = f"{self.instance_url}/secur/frontdoor.jsp?sid={sid}"
1227
+ webbrowser.open(frontdoor_url)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sfq
3
- Version: 0.0.29
3
+ Version: 0.0.31
4
4
  Summary: Python wrapper for the Salesforce's Query API.
5
5
  Author-email: David Moruzzi <sfq.pypi@dmoruzi.com>
6
6
  Keywords: salesforce,salesforce query
@@ -0,0 +1,6 @@
1
+ sfq/__init__.py,sha256=nVBedAMHbX95YE6FcdvjsH_BZ56Ekl855Q_HuIaYoG0,46792
2
+ sfq/_cometd.py,sha256=XimQEubmJwUmbWe85TxH_cuhGvWVuiHHrVr41tguuiI,10508
3
+ sfq/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ sfq-0.0.31.dist-info/METADATA,sha256=RMgCGs9B5xkc9Ci9zOMl3B5peAwdTBzvLExOYOqaclI,6899
5
+ sfq-0.0.31.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ sfq-0.0.31.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- sfq/__init__.py,sha256=PCvN7WBs0krbGc9PUZUYdan3L67iQkZCp77_EvrOGKo,44356
2
- sfq/_cometd.py,sha256=XimQEubmJwUmbWe85TxH_cuhGvWVuiHHrVr41tguuiI,10508
3
- sfq/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- sfq-0.0.29.dist-info/METADATA,sha256=G4tled8wgy1_Rav2UlF4-_T5P54e6Wv0ozi-HZGP9xc,6899
5
- sfq-0.0.29.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
- sfq-0.0.29.dist-info/RECORD,,
File without changes