-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added query params injection to api plugin url & headers
- Loading branch information
1 parent
d25cf30
commit 742e726
Showing
31 changed files
with
2,304 additions
and
655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# kyb-app | ||
|
||
## 0.3.80 | ||
|
||
### Patch Changes | ||
|
||
- @ballerine/workflow-browser-sdk@0.6.65 | ||
|
||
## 0.3.79 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...lugins/external-plugin/api-plugin.test.ts → ...rnal-plugin/api-plugin/api-plugin.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/workflow-core/src/lib/plugins/external-plugin/api-plugin/helpers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { formatStringValues, getGlobalQueryParams, isBrowser } from './helpers'; | ||
|
||
describe('helpers', () => { | ||
describe('isBrowser', () => { | ||
it('should return true when window is defined', () => { | ||
// Mock window object | ||
global.window = {} as Window & typeof globalThis; | ||
|
||
expect(isBrowser()).toBe(true); | ||
|
||
delete global.window; | ||
}); | ||
|
||
it('should return false when window is undefined', () => { | ||
expect(isBrowser()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('getGlobalQueryParams', () => { | ||
it('should return empty object when not in browser', () => { | ||
const result = getGlobalQueryParams(); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should parse URL search params into object', () => { | ||
// Mock window with location | ||
global.window = { | ||
location: { | ||
search: '?key1=value1&key2=value2', | ||
}, | ||
} as Window & typeof globalThis; | ||
|
||
expect(getGlobalQueryParams()).toEqual({ | ||
key1: 'value1', | ||
key2: 'value2', | ||
}); | ||
|
||
delete global.window; | ||
}); | ||
}); | ||
|
||
describe('formatStringValues', () => { | ||
it('should return original string if no placeholders found', () => { | ||
const str = 'Hello World'; | ||
const data = { name: 'John' }; | ||
|
||
expect(formatStringValues(str, data)).toBe(str); | ||
}); | ||
|
||
it('should replace single placeholder with value', () => { | ||
const str = 'Hello {name}'; | ||
const data = { name: 'John' }; | ||
|
||
expect(formatStringValues(str, data)).toBe('Hello John'); | ||
}); | ||
|
||
it('should replace multiple placeholders with values', () => { | ||
const str = 'Hello {user.firstName} {user.lastName}'; | ||
const data = { | ||
user: { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
}, | ||
}; | ||
|
||
expect(formatStringValues(str, data)).toBe('Hello John Doe'); | ||
}); | ||
|
||
it('should keep placeholder if value not found in data', () => { | ||
const str = 'Hello {name} {unknown}'; | ||
const data = { name: 'John' }; | ||
|
||
expect(formatStringValues(str, data)).toBe('Hello John {unknown}'); | ||
}); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
packages/workflow-core/src/lib/plugins/external-plugin/api-plugin/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import get from 'lodash.get'; | ||
|
||
export const isBrowser = () => typeof window !== 'undefined'; | ||
|
||
export const getGlobalQueryParams = () => { | ||
if (!isBrowser()) return {}; | ||
|
||
const searchParams = new URLSearchParams(window.location.search); | ||
const paramsObject: Record<string, string> = {}; | ||
|
||
searchParams.forEach((value, key) => { | ||
paramsObject[key] = value; | ||
}); | ||
|
||
return paramsObject; | ||
}; | ||
|
||
export const formatStringValues = ( | ||
str: string, | ||
data: Record<string, string | Record<string, string>>, | ||
) => { | ||
// Find all placeholders in curly braces | ||
const placeholders = str.match(/{(.*?)}/g); | ||
|
||
if (!placeholders) return str; | ||
|
||
let formattedString = str; | ||
|
||
// Replace each placeholder with its value from data | ||
for (const placeholder of placeholders) { | ||
const path = placeholder.replace(/{|}/g, ''); // Remove curly braces | ||
const value = get(data, path); | ||
|
||
// Replace placeholder with value if found | ||
if (value !== undefined) { | ||
formattedString = formattedString.replace(placeholder, String(value)); | ||
} | ||
} | ||
|
||
return formattedString; | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/workflow-core/src/lib/plugins/external-plugin/api-plugin/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './api-plugin'; |
4 changes: 2 additions & 2 deletions
4
packages/workflow-core/src/lib/plugins/external-plugin/ballerine-email-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
packages/workflow-core/src/lib/plugins/external-plugin/ballerine-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/workflow-core/src/lib/plugins/external-plugin/email-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
packages/workflow-core/src/lib/plugins/external-plugin/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export { ApiPlugin } from './api-plugin'; | ||
export { WebhookPlugin } from './webhook-plugin'; | ||
export { ApiPlugin } from './api-plugin/api-plugin'; | ||
export { DispatchEventPlugin } from './dispatch-event-plugin'; | ||
export type { | ||
WebhookPluginParams, | ||
IApiPluginParams, | ||
ValidatableTransformer, | ||
IterativePluginParams, | ||
SerializableValidatableTransformer, | ||
ValidatableTransformer, | ||
WebhookPluginParams, | ||
} from './types'; | ||
export { WebhookPlugin } from './webhook-plugin'; |
2 changes: 1 addition & 1 deletion
2
packages/workflow-core/src/lib/plugins/external-plugin/kyb-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
packages/workflow-core/src/lib/plugins/external-plugin/kyc-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/workflow-core/src/lib/plugins/external-plugin/kyc-session-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ges/workflow-core/src/lib/plugins/external-plugin/mastercard-merchant-screening-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.