From ebe0c06db0b0a8eaade1735e364463e7759ebda4 Mon Sep 17 00:00:00 2001 From: Gurvinder Singh Date: Wed, 23 Apr 2025 14:18:30 -0400 Subject: [PATCH 1/2] Use internal runners --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 368497e..73cc42c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: version: [22, 20, 18, 16, 14] - os: [windows-latest, macos-latest-large, ubuntu-latest] + os: [sfdc-hk-windows-latest, sfdc-hk-macos-latest-large, sfdc-hk-ubuntu-latest] name: Node ${{ matrix.version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} steps: From c0d2e431bb99ddb2650d6096a5fc9131614192c3 Mon Sep 17 00:00:00 2001 From: Gurvinder Singh Date: Wed, 23 Apr 2025 14:28:21 -0400 Subject: [PATCH 2/2] Run format:write --- .github/workflows/build.yml | 7 +- .vscode/launch.json | 68 ++++++++--------- bin/bump-version.js | 15 +++- src/add-ons/heroku-applink.ts | 27 ++++--- src/index.ts | 9 +-- src/sdk/bulk-api.ts | 2 +- src/sdk/context.ts | 2 +- src/sdk/data-api.ts | 6 +- src/sdk/data-cloud-api.ts | 125 ++++++++++++++++---------------- src/sdk/org.ts | 17 +++-- src/utils/create-connections.ts | 2 +- src/utils/request.ts | 4 +- test/logger.ts | 20 +++-- test/sdk/bulk-api.test.ts | 2 +- tsconfig.json | 4 +- 15 files changed, 166 insertions(+), 144 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 73cc42c..22537f9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,12 @@ jobs: fail-fast: false matrix: version: [22, 20, 18, 16, 14] - os: [sfdc-hk-windows-latest, sfdc-hk-macos-latest-large, sfdc-hk-ubuntu-latest] + os: + [ + sfdc-hk-windows-latest, + sfdc-hk-macos-latest-large, + sfdc-hk-ubuntu-latest, + ] name: Node ${{ matrix.version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} steps: diff --git a/.vscode/launch.json b/.vscode/launch.json index 81b6627..d53cffb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,39 +1,31 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Attach", - "port": 9230, - "request": "attach", - "skipFiles": [ - "/**" - ], - "type": "node" - }, - { - "name": "Attach by Process ID", - "processId": "${command:PickProcess}", - "request": "attach", - "skipFiles": [ - "/**" - ], - "type": "node" - }, - { - "type": "node", - "request": "launch", - "name": "Launch Program", - "skipFiles": [ - "/**" - ], - "program": "${file}", - "preLaunchTask": "tsc: build - tsconfig.json", - "outFiles": [ - "${workspaceFolder}/dist/**/*.js" - ] - } - ] -} \ No newline at end of file + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Attach", + "port": 9230, + "request": "attach", + "skipFiles": ["/**"], + "type": "node" + }, + { + "name": "Attach by Process ID", + "processId": "${command:PickProcess}", + "request": "attach", + "skipFiles": ["/**"], + "type": "node" + }, + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": ["/**"], + "program": "${file}", + "preLaunchTask": "tsc: build - tsconfig.json", + "outFiles": ["${workspaceFolder}/dist/**/*.js"] + } + ] +} diff --git a/bin/bump-version.js b/bin/bump-version.js index f7e7c3b..c31247a 100644 --- a/bin/bump-version.js +++ b/bin/bump-version.js @@ -4,10 +4,15 @@ import { readFile, readFileSync, writeFileSync } from "fs"; import { exec } from "child_process"; const version = process.argv[2]; -const semver = new RegExp(/^((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?)$/); +const semver = new RegExp( + /^((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)?)$/ +); if (!version.match(semver)) { - console.error("Please use a valid numeric semver string:", "https://semver.org/"); + console.error( + "Please use a valid numeric semver string:", + "https://semver.org/" + ); process.exit(1); } @@ -24,13 +29,15 @@ readFile("./package.json", (err, jsonString) => { // bump CHANGELOG console.log("Bumping version in CHANGELOG.md..."); -const changelog = readFileSync('./CHANGELOG.md').toString().split("## [Unreleased]"); +const changelog = readFileSync("./CHANGELOG.md") + .toString() + .split("## [Unreleased]"); const today = new Date(); // JS doesn't support custom date formatting strings such as 'YYYY-MM-DD', so the best we can // do is extract the date from the ISO 8601 string (which is YYYY-MM-DDTHH:mm:ss.sssZ). // As an added bonus this uses UTC, ensuring consistency regardless of which machine runs this script. -const date = today.toISOString().split("T")[0] +const date = today.toISOString().split("T")[0]; changelog.splice(1, 0, `## [Unreleased]\n\n## [${version}] - ${date}`); writeFileSync("./CHANGELOG.md", changelog.join("")); diff --git a/src/add-ons/heroku-applink.ts b/src/add-ons/heroku-applink.ts index b5af11b..984707c 100644 --- a/src/add-ons/heroku-applink.ts +++ b/src/add-ons/heroku-applink.ts @@ -21,32 +21,37 @@ export async function getConnection(name: string): Promise { throw Error(`Connection name not provided`); } - const addonEndpoint = process.env.HEROKU_APPLINK_API_URL || process.env.HEROKU_APPLINK_STAGING_API_URL; + const addonEndpoint = + process.env.HEROKU_APPLINK_API_URL || + process.env.HEROKU_APPLINK_STAGING_API_URL; if (!addonEndpoint) { - throw Error(`Heroku Applink add-on not provisioned on app or endpoint not provided`); + throw Error( + `Heroku Applink add-on not provisioned on app or endpoint not provided` + ); } const addonAuthToken = process.env.HEROKU_APPLINK_TOKEN; if (!addonAuthToken) { - throw Error(`Heroku Applink add-on not provisioned on app or authorization token not found`); + throw Error( + `Heroku Applink add-on not provisioned on app or authorization token not found` + ); } const authUrl = `${addonEndpoint}/invocations/authorization`; const opts = { - method: 'POST', + method: "POST", headers: { - 'Authorization': `Bearer ${addonAuthToken}`, - 'Content-Type': 'application/json' + Authorization: `Bearer ${addonAuthToken}`, + "Content-Type": "application/json", }, body: JSON.stringify({ - 'org_name': name + org_name: name, }), retry: { - limit: 1 - } + limit: 1, + }, }; - let response; try { response = await HTTP_REQUEST.request(authUrl, opts); @@ -69,4 +74,4 @@ export async function getConnection(name: string): Promise { response.datacloud_token, response.datacloud_instance_url ); -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 22b0a27..73f9606 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,11 +25,11 @@ export function init() { return { addons: { applink: { - getConnection - } + getConnection, + }, }, dataCloud: { - parseDataActionEvent + parseDataActionEvent, }, salesforce: { parseRequest, @@ -100,7 +100,7 @@ export function parseRequest( * @property body The request's body * @returns {DataCloudActionEvent} */ -export function parseDataActionEvent(payload: any) : DataCloudActionEvent { +export function parseDataActionEvent(payload: any): DataCloudActionEvent { return payload as DataCloudActionEvent; } @@ -1100,7 +1100,6 @@ export interface DataCloudUpsertResponse { } export interface DataCloudApi { - /** * {@link https://developer.salesforce.com/docs/atlas.en-us.c360a_api.meta/c360a_api/c360a_api_query_v2.htm | Data Cloud Query API} * * @param sql diff --git a/src/sdk/bulk-api.ts b/src/sdk/bulk-api.ts index 648d024..be7291f 100644 --- a/src/sdk/bulk-api.ts +++ b/src/sdk/bulk-api.ts @@ -591,4 +591,4 @@ class BulkApiClient extends HttpApi { message: body[0].message, }; } -} \ No newline at end of file +} diff --git a/src/sdk/context.ts b/src/sdk/context.ts index 081f6c0..ef6b1b7 100644 --- a/src/sdk/context.ts +++ b/src/sdk/context.ts @@ -20,7 +20,7 @@ export class ContextImpl implements Context { orgId: string, orgDomainUrl: string, userId: string, - username: string, + username: string ) { this.id = id; this.org = new OrgImpl( diff --git a/src/sdk/data-api.ts b/src/sdk/data-api.ts index fb6608b..4b61930 100644 --- a/src/sdk/data-api.ts +++ b/src/sdk/data-api.ts @@ -28,9 +28,7 @@ export class DataApiImpl implements DataApi { private conn: Connection; private readonly domainUrl: string; - constructor(accessToken: string, - apiVersion: string, - domainUrl: string) { + constructor(accessToken: string, apiVersion: string, domainUrl: string) { this.accessToken = accessToken; this.apiVersion = apiVersion; this.domainUrl = domainUrl; @@ -41,7 +39,7 @@ export class DataApiImpl implements DataApi { this.conn = new Connection({ accessToken: this.accessToken, instanceUrl: this.domainUrl, - version: this.apiVersion + version: this.apiVersion, }); } diff --git a/src/sdk/data-cloud-api.ts b/src/sdk/data-cloud-api.ts index de39df6..2c0ca68 100644 --- a/src/sdk/data-cloud-api.ts +++ b/src/sdk/data-cloud-api.ts @@ -6,72 +6,75 @@ */ import { - DataCloudApi, - DataCloudQuery, - DataCloudQueryResponse, - DataCloudUpsertResponse, + DataCloudApi, + DataCloudQuery, + DataCloudQueryResponse, + DataCloudUpsertResponse, } from "../index.js"; import { HttpRequestUtil } from "../utils/request"; export class DataCloudApiImpl implements DataCloudApi { - readonly accessToken: string; - private readonly domainUrl: string; - private request: HttpRequestUtil; + readonly accessToken: string; + private readonly domainUrl: string; + private request: HttpRequestUtil; - constructor(accessToken: string, - domainUrl: string) { - this.accessToken = accessToken; - this.domainUrl = domainUrl; - this.request = new HttpRequestUtil(); - } + constructor(accessToken: string, domainUrl: string) { + this.accessToken = accessToken; + this.domainUrl = domainUrl; + this.request = new HttpRequestUtil(); + } - async query(sql: DataCloudQuery): Promise { - const url = `${this.domainUrl}/api/v2/query`; - const opts = { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${this.accessToken}` - }, - retry: { - limit: 1 - }, - json: sql - }; - const response = await this.request.request(url, opts); - return response as DataCloudQueryResponse; - } + async query(sql: DataCloudQuery): Promise { + const url = `${this.domainUrl}/api/v2/query`; + const opts = { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${this.accessToken}`, + }, + retry: { + limit: 1, + }, + json: sql, + }; + const response = await this.request.request(url, opts); + return response as DataCloudQueryResponse; + } - async queryNextBatch(nextBatchId: string): Promise { - const url = `${this.domainUrl}/api/v2/query/${nextBatchId}`; - const opts = { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${this.accessToken}` - }, - retry: { - limit: 1 - } - }; - const response = await this.request.request(url, opts); - return response as DataCloudQueryResponse; - } + async queryNextBatch(nextBatchId: string): Promise { + const url = `${this.domainUrl}/api/v2/query/${nextBatchId}`; + const opts = { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${this.accessToken}`, + }, + retry: { + limit: 1, + }, + }; + const response = await this.request.request(url, opts); + return response as DataCloudQueryResponse; + } - async upsert(name: string, objectName: string, data: any): Promise { - const url = `${this.domainUrl}/api/v1/ingest/sources/${name}/${objectName}`; - const opts = { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${this.accessToken}` - }, - retry: { - limit: 1 - }, - json: data - }; - const response = await this.request.request(url, opts); - return response as DataCloudUpsertResponse; - } -} \ No newline at end of file + async upsert( + name: string, + objectName: string, + data: any + ): Promise { + const url = `${this.domainUrl}/api/v1/ingest/sources/${name}/${objectName}`; + const opts = { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${this.accessToken}`, + }, + retry: { + limit: 1, + }, + json: data, + }; + const response = await this.request.request(url, opts); + return response as DataCloudUpsertResponse; + } +} diff --git a/src/sdk/org.ts b/src/sdk/org.ts index f4a26f2..3e539d7 100644 --- a/src/sdk/org.ts +++ b/src/sdk/org.ts @@ -37,10 +37,15 @@ export class OrgImpl implements Org { dataCloudInstanceUrl?: string ) { this.accessToken = accessToken; - this.apiVersion = apiVersion.startsWith('v') ? apiVersion.substring(1) : apiVersion; - this.domainUrl = orgDomainUrl.startsWith('http') ? orgDomainUrl : `https://${orgDomainUrl}`; + this.apiVersion = apiVersion.startsWith("v") + ? apiVersion.substring(1) + : apiVersion; + this.domainUrl = orgDomainUrl.startsWith("http") + ? orgDomainUrl + : `https://${orgDomainUrl}`; this.id = orgId; - this.namespace = namespace === null || namespace === 'null' ? '' : namespace; + this.namespace = + namespace === null || namespace === "null" ? "" : namespace; this.bulkApi = createBulkApi({ instanceUrl: this.domainUrl, @@ -65,13 +70,13 @@ export class OrgImpl implements Org { } async request(fullUrlOrUrlPart: string, opts: any, json = true) { - const url = fullUrlOrUrlPart.startsWith('http') + const url = fullUrlOrUrlPart.startsWith("http") ? fullUrlOrUrlPart : `${this.domainUrl}/${fullUrlOrUrlPart}`; const updatedOpts = opts || {}; updatedOpts.headers = updatedOpts.headers || {}; - if (!updatedOpts.headers['Authorization']) { - updatedOpts.headers['Authorization'] = `Bearer ${this.accessToken}`; + if (!updatedOpts.headers["Authorization"]) { + updatedOpts.headers["Authorization"] = `Bearer ${this.accessToken}`; } return HTTP_REQUEST.request(url, updatedOpts, json); diff --git a/src/utils/create-connections.ts b/src/utils/create-connections.ts index 98570ae..12e654d 100644 --- a/src/utils/create-connections.ts +++ b/src/utils/create-connections.ts @@ -23,4 +23,4 @@ export function createConnection(options: CreateConnectionOptions) { client: `salesforce-sdk-nodejs-v1:${process.env.npm_package_version}`, }, }); -} \ No newline at end of file +} diff --git a/src/utils/request.ts b/src/utils/request.ts index f408746..5625452 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -5,7 +5,7 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import fetch from 'node-fetch'; +import fetch from "node-fetch"; /** * Handles HTTP requests. @@ -15,4 +15,4 @@ export class HttpRequestUtil { const response = await fetch(url, opts); return json ? response.json() : response; } -} \ No newline at end of file +} diff --git a/test/logger.ts b/test/logger.ts index 525cf70..90c2f8d 100644 --- a/test/logger.ts +++ b/test/logger.ts @@ -33,30 +33,40 @@ describe("Logger", () => { }); describe("Logger levels", () => { it("should set the log level to a number: 50 for Error", async () => { - const errorlogger = (await baseLogger.child("testLogger")).useMemoryLogging(); + const errorlogger = ( + await baseLogger.child("testLogger") + ).useMemoryLogging(); errorlogger.error("test Error"); const logRecords = errorlogger.getBufferedRecords(); expect(logRecords[0]).to.have.property("level", 50); }); it("should set the log level to a number: 40 for Warn", async () => { - const warnlogger = (await baseLogger.child("testLogger")).useMemoryLogging(); + const warnlogger = ( + await baseLogger.child("testLogger") + ).useMemoryLogging(); warnlogger.warn("test warn"); const logRecords = warnlogger.getBufferedRecords(); expect(logRecords[0]).to.have.property("level", 40); }); it("should set the log level to a number: 30 for Info", async () => { - const infologger = (await baseLogger.child("testLogger")).useMemoryLogging(); + const infologger = ( + await baseLogger.child("testLogger") + ).useMemoryLogging(); infologger.info("test info"); const logRecords = infologger.getBufferedRecords(); expect(logRecords[0]).to.have.property("level", 30); }); it("should set the log level to a number: 20 for Debug", async () => { - const debuglogger = (await baseLogger.child("testLogger")).useMemoryLogging(); + const debuglogger = ( + await baseLogger.child("testLogger") + ).useMemoryLogging(); debuglogger.setLevel(20); expect(debuglogger.getLevel()).to.equal(LoggerLevel.DEBUG); }); it("should set the log level to a number: 10 for Trace", async () => { - const tracelogger = (await baseLogger.child("testLogger")).useMemoryLogging(); + const tracelogger = ( + await baseLogger.child("testLogger") + ).useMemoryLogging(); tracelogger.setLevel(10); expect(tracelogger.getLevel()).to.equal(LoggerLevel.TRACE); }); diff --git a/test/sdk/bulk-api.test.ts b/test/sdk/bulk-api.test.ts index fe82546..eecb149 100644 --- a/test/sdk/bulk-api.test.ts +++ b/test/sdk/bulk-api.test.ts @@ -1152,4 +1152,4 @@ function expectBulkApiError( } else { expect.fail("was expecting an bulk api error"); } -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 7f4e8cc..52365a3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,9 +17,7 @@ "removeComments": true, "declaration": true, "paths": { - "~/*": [ - "./src/*" - ] + "~/*": ["./src/*"] } }, "exclude": ["node_modules", "test", "fixtures", "dist"]