From 4a2a68274e8d985051cff4f881d19d97c3672b14 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Thu, 29 Nov 2018 18:58:37 -0700 Subject: [PATCH 1/3] Add getCurrentIpAddress action --- __tests__/actions/getCurrentIpAddress.spec.ts | 22 ++++++++++ src/actions/getCurrentIpAddress.ts | 40 +++++++++++++++++++ src/actions/index.ts | 2 + src/interfaces/WF/WFIPAddressAddress.ts | 9 +++++ src/interfaces/WF/WFIPAddressType.ts | 9 +++++ .../WF/WFWorkflowActionIdentifier.ts | 1 + .../WF/WFWorkflowActionParameters.ts | 4 ++ 7 files changed, 87 insertions(+) create mode 100644 __tests__/actions/getCurrentIpAddress.spec.ts create mode 100644 src/actions/getCurrentIpAddress.ts create mode 100644 src/interfaces/WF/WFIPAddressAddress.ts create mode 100644 src/interfaces/WF/WFIPAddressType.ts diff --git a/__tests__/actions/getCurrentIpAddress.spec.ts b/__tests__/actions/getCurrentIpAddress.spec.ts new file mode 100644 index 00000000..fb7ca17a --- /dev/null +++ b/__tests__/actions/getCurrentIpAddress.spec.ts @@ -0,0 +1,22 @@ +import { getCurrentIpAddress } from '../../src/actions'; + +describe('getCurrentIpAddress function', () => { + + it('is a function', () => { + expect(typeof getCurrentIpAddress).toBe('function'); + }); + + it('builds a getCurrentIpAddress action', () => { + const expected = { + WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress', + WFWorkflowActionParameters: { + WFIPAddressSourceOption: 'External', + WFIPAddressTypeOption: 'IPv4', + }, + }; + const actual = getCurrentIpAddress({}); + + expect(actual).toEqual(expected); + }); + +}); diff --git a/src/actions/getCurrentIpAddress.ts b/src/actions/getCurrentIpAddress.ts new file mode 100644 index 00000000..00c44ec8 --- /dev/null +++ b/src/actions/getCurrentIpAddress.ts @@ -0,0 +1,40 @@ +import { withActionOutput } from '../utils'; + +import WFIPAddressSourceOption from '../interfaces/WF/WFIPAddressAddress'; +import WFIPAddressTypeOption from '../interfaces/WF/WFIPAddressType'; +import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; + +/** + * Get Current IP Address Action. Returns the current public IP address of the + * device. + * + * ```js + * getCurrentIpAddress({ + * 'address': 'External', + * 'type': 'IPv4', + * }); + * ``` + */ +const getCurrentIpAddress = ( + options: { + /** The address (public or private) to get */ + address?: WFIPAddressSourceOption, + /** The type of address to get */ + type?: WFIPAddressTypeOption, + }, +): WFWorkflowAction => { + const { + address = 'External', + type = 'IPv4', + } = options; + + return { + WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress', + WFWorkflowActionParameters: { + WFIPAddressSourceOption: address, + WFIPAddressTypeOption: type, + }, + }; +}; + +export default withActionOutput(getCurrentIpAddress); diff --git a/src/actions/index.ts b/src/actions/index.ts index 20d8643b..696d4682 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -9,6 +9,7 @@ import count from './count'; import exitShortcut from './exitShortcut'; import getBatteryLevel from './getBatteryLevel'; import getContentsOfUrl from './getContentsOfUrl'; +import getCurrentIpAddress from './getCurrentIpAddress'; import getDictionaryValue from './getDictionaryValue'; import getName from './getName'; import getType from './getType'; @@ -43,6 +44,7 @@ export { exitShortcut, getBatteryLevel, getContentsOfUrl, + getCurrentIpAddress, getDictionaryValue, getName, getType, diff --git a/src/interfaces/WF/WFIPAddressAddress.ts b/src/interfaces/WF/WFIPAddressAddress.ts new file mode 100644 index 00000000..592e2bf0 --- /dev/null +++ b/src/interfaces/WF/WFIPAddressAddress.ts @@ -0,0 +1,9 @@ +/** + * @typedef {('External'|'Local')} WFIPAddressSourceOption + */ +type WFIPAddressSourceOption = ( + 'External' + | 'Local' +); + +export default WFIPAddressSourceOption; diff --git a/src/interfaces/WF/WFIPAddressType.ts b/src/interfaces/WF/WFIPAddressType.ts new file mode 100644 index 00000000..c40e0768 --- /dev/null +++ b/src/interfaces/WF/WFIPAddressType.ts @@ -0,0 +1,9 @@ +/** + * @typedef {('IPv4'|'IPv6')} WFIPAddressTypeOption + */ +type WFIPAddressTypeOption = ( + 'IPv4' + | 'IPv6' +); + +export default WFIPAddressTypeOption; diff --git a/src/interfaces/WF/WFWorkflowActionIdentifier.ts b/src/interfaces/WF/WFWorkflowActionIdentifier.ts index 23efab33..6c8581c5 100644 --- a/src/interfaces/WF/WFWorkflowActionIdentifier.ts +++ b/src/interfaces/WF/WFWorkflowActionIdentifier.ts @@ -11,6 +11,7 @@ type WFWorkflowActionIdentifier = ( | 'is.workflow.actions.exit' | 'is.workflow.actions.flashlight' | 'is.workflow.actions.getbatterylevel' + | 'is.workflow.actions.getipaddress' | 'is.workflow.actions.getitemname' | 'is.workflow.actions.getitemtype' | 'is.workflow.actions.gettext' diff --git a/src/interfaces/WF/WFWorkflowActionParameters.ts b/src/interfaces/WF/WFWorkflowActionParameters.ts index c0e86c3b..e3cfe6b7 100644 --- a/src/interfaces/WF/WFWorkflowActionParameters.ts +++ b/src/interfaces/WF/WFWorkflowActionParameters.ts @@ -6,6 +6,8 @@ import WFGetDictionaryValueType from './WFGetDictionaryValueType'; import WFHTTPBodyType from './WFHTTPBodyType'; import WFHTTPMethod from './WFHTTPMethod'; import WFInputType from './WFInputType'; +import WFIPAddressSourceOption from './WFIPAddressAddress'; +import WFIPAddressTypeOption from './WFIPAddressType'; import WFMathOperation from './WFMathOperation'; import WFSerialization from './WFSerialization'; @@ -36,6 +38,8 @@ interface WFWorkflowActionParameters { WFHTTPHeaders?: WFSerialization; WFHTTPMethod?: WFHTTPMethod; WFInputType?: WFInputType; + WFIPAddressSourceOption?: WFIPAddressSourceOption; + WFIPAddressTypeOption?: WFIPAddressTypeOption; WFJSONValues?: WFSerialization; WFMathOperand?: number; WFMathOperation?: WFMathOperation; From e47c82427db2352dfadd054f31e1589c0700de89 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Fri, 30 Nov 2018 12:35:58 -0700 Subject: [PATCH 2/3] Owner comments --- __tests__/actions/getCurrentIpAddress.spec.ts | 26 +++++++++++++++++++ src/actions/getCurrentIpAddress.ts | 4 +-- ...sAddress.ts => WFIPAddressSourceOption.ts} | 3 --- ...ddressType.ts => WFIPAddressTypeOption.ts} | 3 --- .../WF/WFWorkflowActionParameters.ts | 4 +-- 5 files changed, 30 insertions(+), 10 deletions(-) rename src/interfaces/WF/{WFIPAddressAddress.ts => WFIPAddressSourceOption.ts} (60%) rename src/interfaces/WF/{WFIPAddressType.ts => WFIPAddressTypeOption.ts} (60%) diff --git a/__tests__/actions/getCurrentIpAddress.spec.ts b/__tests__/actions/getCurrentIpAddress.spec.ts index fb7ca17a..d8794750 100644 --- a/__tests__/actions/getCurrentIpAddress.spec.ts +++ b/__tests__/actions/getCurrentIpAddress.spec.ts @@ -19,4 +19,30 @@ describe('getCurrentIpAddress function', () => { expect(actual).toEqual(expected); }); + it('builds a getCurrentIpAddress action when an address is passed', () => { + const expected = { + WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress', + WFWorkflowActionParameters: { + WFIPAddressSourceOption: 'Local', + WFIPAddressTypeOption: 'IPv4', + }, + }; + const actual = getCurrentIpAddress({ address: 'Local' }); + + expect(actual).toEqual(expected); + }); + + it('builds a getCurrentIpAddress action when a type is passed', () => { + const expected = { + WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress', + WFWorkflowActionParameters: { + WFIPAddressSourceOption: 'External', + WFIPAddressTypeOption: 'IPv6', + }, + }; + const actual = getCurrentIpAddress({ type: 'IPv6' }); + + expect(actual).toEqual(expected); + }); + }); diff --git a/src/actions/getCurrentIpAddress.ts b/src/actions/getCurrentIpAddress.ts index 00c44ec8..2ec4c067 100644 --- a/src/actions/getCurrentIpAddress.ts +++ b/src/actions/getCurrentIpAddress.ts @@ -1,7 +1,7 @@ import { withActionOutput } from '../utils'; -import WFIPAddressSourceOption from '../interfaces/WF/WFIPAddressAddress'; -import WFIPAddressTypeOption from '../interfaces/WF/WFIPAddressType'; +import WFIPAddressSourceOption from '../interfaces/WF/WFIPAddressSourceOption'; +import WFIPAddressTypeOption from '../interfaces/WF/WFIPAddressTypeOption'; import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; /** diff --git a/src/interfaces/WF/WFIPAddressAddress.ts b/src/interfaces/WF/WFIPAddressSourceOption.ts similarity index 60% rename from src/interfaces/WF/WFIPAddressAddress.ts rename to src/interfaces/WF/WFIPAddressSourceOption.ts index 592e2bf0..c26df211 100644 --- a/src/interfaces/WF/WFIPAddressAddress.ts +++ b/src/interfaces/WF/WFIPAddressSourceOption.ts @@ -1,6 +1,3 @@ -/** - * @typedef {('External'|'Local')} WFIPAddressSourceOption - */ type WFIPAddressSourceOption = ( 'External' | 'Local' diff --git a/src/interfaces/WF/WFIPAddressType.ts b/src/interfaces/WF/WFIPAddressTypeOption.ts similarity index 60% rename from src/interfaces/WF/WFIPAddressType.ts rename to src/interfaces/WF/WFIPAddressTypeOption.ts index c40e0768..b1be27e1 100644 --- a/src/interfaces/WF/WFIPAddressType.ts +++ b/src/interfaces/WF/WFIPAddressTypeOption.ts @@ -1,6 +1,3 @@ -/** - * @typedef {('IPv4'|'IPv6')} WFIPAddressTypeOption - */ type WFIPAddressTypeOption = ( 'IPv4' | 'IPv6' diff --git a/src/interfaces/WF/WFWorkflowActionParameters.ts b/src/interfaces/WF/WFWorkflowActionParameters.ts index e3cfe6b7..2714bf82 100644 --- a/src/interfaces/WF/WFWorkflowActionParameters.ts +++ b/src/interfaces/WF/WFWorkflowActionParameters.ts @@ -6,8 +6,8 @@ import WFGetDictionaryValueType from './WFGetDictionaryValueType'; import WFHTTPBodyType from './WFHTTPBodyType'; import WFHTTPMethod from './WFHTTPMethod'; import WFInputType from './WFInputType'; -import WFIPAddressSourceOption from './WFIPAddressAddress'; -import WFIPAddressTypeOption from './WFIPAddressType'; +import WFIPAddressSourceOption from './WFIPAddressSourceOption'; +import WFIPAddressTypeOption from './WFIPAddressTypeOption'; import WFMathOperation from './WFMathOperation'; import WFSerialization from './WFSerialization'; From 4c168f578c3a1bf2df17e65159809422e8c226db Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Fri, 30 Nov 2018 13:52:39 -0700 Subject: [PATCH 3/3] Updated incorrect docstring --- src/actions/getCurrentIpAddress.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actions/getCurrentIpAddress.ts b/src/actions/getCurrentIpAddress.ts index 2ec4c067..cb7c035d 100644 --- a/src/actions/getCurrentIpAddress.ts +++ b/src/actions/getCurrentIpAddress.ts @@ -5,8 +5,8 @@ import WFIPAddressTypeOption from '../interfaces/WF/WFIPAddressTypeOption'; import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; /** - * Get Current IP Address Action. Returns the current public IP address of the - * device. + * Get Current IP Address Action. Returns the public/private IPv4 or IPv6 + * address of the device. * * ```js * getCurrentIpAddress({