diff --git a/lib/commands/command.ts b/lib/commands/command.ts index 8bbccd9..a574699 100644 --- a/lib/commands/command.ts +++ b/lib/commands/command.ts @@ -125,3 +125,10 @@ export type ObjectInput = { } export type ObjectOutput = { identity: string, uuid?: string } | { key: Key } + +/** + * State input for stateful command + */ +export type CommandState = { + [key: string]: any +} diff --git a/lib/commands/std-account-list.ts b/lib/commands/std-account-list.ts index fd8440d..e00fab9 100644 --- a/lib/commands/std-account-list.ts +++ b/lib/commands/std-account-list.ts @@ -1,6 +1,14 @@ /* Copyright (c) 2021. SailPoint Technologies, Inc. All rights reserved. */ -import { Attributes, ObjectOutput } from './command' +import { Attributes, CommandState, ObjectOutput } from './command' + +/** + * Input object of `std:account:list` command + */ +export type StdAccountListInput = { + stateful?: boolean + state?: CommandState +} /** * Output object of `std:account:list` command @@ -8,5 +16,6 @@ import { Attributes, ObjectOutput } from './command' export type StdAccountListOutput = ObjectOutput & { disabled?: boolean locked?: boolean + deleted?: boolean attributes: Attributes } diff --git a/lib/commands/std-entitlement-list.ts b/lib/commands/std-entitlement-list.ts index a8e2924..d18eae2 100644 --- a/lib/commands/std-entitlement-list.ts +++ b/lib/commands/std-entitlement-list.ts @@ -1,12 +1,14 @@ /* Copyright (c) 2021. SailPoint Technologies, Inc. All rights reserved. */ -import { Attributes, ObjectOutput } from './command' +import { Attributes, CommandState, ObjectOutput } from './command' /** * Input object of `std:entitlement:list` command */ export type StdEntitlementListInput = { type: string + stateful?: boolean + state?: CommandState } /** @@ -14,5 +16,6 @@ export type StdEntitlementListInput = { */ export type StdEntitlementListOutput = ObjectOutput & { type: string + deleted?: boolean attributes: Attributes } diff --git a/lib/connector.spec.ts b/lib/connector.spec.ts index 87419ae..17e85fa 100644 --- a/lib/connector.spec.ts +++ b/lib/connector.spec.ts @@ -185,7 +185,10 @@ describe('exec handlers', () => { StandardCommand.StdTestConnection, MOCK_CONTEXT, undefined, - new PassThrough({ objectMode: true }).on('data', (chunk) => expect(chunk).toStrictEqual({})) + new PassThrough({ objectMode: true }).on('data', (chunk) => expect(chunk).toEqual({ + "type": "output", + "data": {}, + })) ) }) @@ -207,7 +210,10 @@ describe('exec handlers', () => { mockFS.restore() const out = res.read(1) - expect(out).toStrictEqual({"specification": spec}) + expect(out).toEqual({ + "type": "output", + "data": {"specification": spec}, + }) }) it('should execute custom handler', async () => { diff --git a/lib/handler.ts b/lib/handler.ts index 4161e13..3e72bf0 100644 --- a/lib/handler.ts +++ b/lib/handler.ts @@ -24,6 +24,7 @@ import { StdTestConnectionOutput, StdChangePasswordInput, StdChangePasswordOutput, + StdAccountListInput } from './commands' import { Response } from './response' @@ -67,7 +68,7 @@ export type StdAccountEnableHandler = ( ) => Promise export type StdAccountListHandler = ( context: Context, - input: undefined, + input: StdAccountListInput, res: Response ) => Promise export type StdAccountReadHandler = ( diff --git a/lib/response/index.ts b/lib/response/index.ts index c2e04af..c832d08 100644 --- a/lib/response/index.ts +++ b/lib/response/index.ts @@ -7,6 +7,7 @@ import { Writable } from 'stream' */ export interface Response { send(output: T): void + saveState(state: any): void } /** @@ -24,6 +25,35 @@ export class ResponseStream implements Response { * @param chunk output chunk */ send(chunk: T): void { - this._writable.write(chunk) + this._writable.write(new RawResponse(chunk)) + } + + /** + * Save state for stateful command + * @param state the end state of running the stateful command + */ + saveState(state: any): void { + this._writable.write(new RawResponse(state, ResponseType.State)) + } +} + +/** + * Enum representing different types of responses + */ +enum ResponseType { + Output = 'output', + State = 'state' +} + +/** + * RawResponse is the response that sdk sends out as command output + */ +class RawResponse { + type: ResponseType + data: string + + constructor(data: any, type = ResponseType.Output) { + this.data = data + this.type = type } }