ofsc-utility-browser 1.0.21 → 1.0.22

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.
@@ -27,3 +27,8 @@ export declare function xmlNodeToObjects(xmlString: string, parentNodeName: stri
27
27
  * @param csvData Array of objects representing CSV rows
28
28
  */
29
29
  export declare const downloadCSV: (csvData: CSVRow[], name?: string) => void;
30
+ type DateRange = {
31
+ start: string;
32
+ end: string;
33
+ };
34
+ export declare const getLast90DaysChunks: () => DateRange[];
@@ -66,12 +66,13 @@ export const fetchWithRetry = async (url, clientId, clientSecret, instanceUrl, t
66
66
  token
67
67
  };
68
68
  }
69
+ console.info(res.status);
69
70
  /* ---------- 429: retry with backoff ---------- */
70
- if (res.status === 429 && retries > 0) {
71
+ if (res.status === 429 && retries > 0 || res.status === 422 && retries > 0) {
71
72
  const retryAfter = res.headers.get("Retry-After");
72
- console.log("⚠️ 429 received. Retrying...", retryAfter);
73
+ console.log("⚠️ 429 / 422 received. Retrying...", retryAfter);
73
74
  const delay = retryAfter ? Number(retryAfter) * 1000 : baseDelay;
74
- console.warn(`⚠️ 429 received. Retrying in ${delay}ms... (${retries} left)`);
75
+ console.warn(`⚠️ 429 / 422 received. Retrying in ${delay}ms... (${retries} left)`);
75
76
  await new Promise(r => setTimeout(r, delay));
76
77
  return fetchWithRetry(url, clientId, clientSecret, instanceUrl, token, retries - 1, baseDelay * 2);
77
78
  }
@@ -156,3 +157,28 @@ export const downloadCSV = (csvData, name = "data") => {
156
157
  function showStatus(message, type) {
157
158
  console.log(`[${type.toUpperCase()}] ${message}`);
158
159
  }
160
+ const formatDate = (date) => {
161
+ return date.toISOString().split('T')[0];
162
+ };
163
+ export const getLast90DaysChunks = () => {
164
+ const result = [];
165
+ const today = new Date();
166
+ today.setHours(0, 0, 0, 0);
167
+ const startBase = new Date(today);
168
+ startBase.setDate(today.getDate() - 89);
169
+ for (let i = 0; i < 3; i++) {
170
+ const rangeStart = new Date(startBase);
171
+ rangeStart.setDate(startBase.getDate() + i * 30);
172
+ const rangeEnd = new Date(rangeStart);
173
+ rangeEnd.setDate(rangeStart.getDate() + 29);
174
+ // clamp end to today (important for safety)
175
+ if (rangeEnd > today) {
176
+ rangeEnd.setTime(today.getTime());
177
+ }
178
+ result.push({
179
+ start: formatDate(rangeStart),
180
+ end: formatDate(rangeEnd)
181
+ });
182
+ }
183
+ return result;
184
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofsc-utility-browser",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "A wrapper for Oracle Field Service REST API for browser cdn for html",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -25,7 +25,12 @@ A lightweight utility library for interacting with **Oracle Field Service Cloud
25
25
 
26
26
  ## Functions implemented
27
27
 
28
- ### Activity
28
+ ### Samples
29
+ ```
30
+ https://github.com/mailtodanish/ofsc-utility-browser/tree/main/sample
31
+ ```
32
+
33
+ ### Methods
29
34
 
30
35
  - getAllActivities(clientId: string,clientSecret: string,instanceUrl: string,resources: string,dateFrom: string,dateTo: string,q?: string,fields?: string,ncludeNonScheduled: boolean = false )
31
36
  - getActivitybyId( clientId: string, clientSecret: string,instanceUrl: string, activityId: number, token: string=")