From 0956b831e30d3ab7a430d1f6a7479d98cf936acb Mon Sep 17 00:00:00 2001 From: Oleksandr Pravosudko <71440851+oleksandrpravosudko-okta@users.noreply.github.com> Date: Wed, 7 Dec 2022 17:46:51 +0100 Subject: [PATCH] fix: allow custom attributes for extensible types (#365) OKTA-550323 fix: allow custom attributes for extensible types --- CHANGELOG.md | 4 ++-- src/types/custom-attributes.d.ts | 18 ++++++++++++++++++ src/types/models/GroupProfile.d.ts | 2 ++ src/types/models/InlineHookPayload.d.ts | 2 ++ src/types/models/SmsTemplateTranslations.d.ts | 2 ++ src/types/models/UserProfile.d.ts | 2 ++ templates/model.d.ts.hbs | 6 ++++++ test/type/user-profile.test-d.ts | 10 ++++++++++ yarn.lock | 2 +- 9 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/types/custom-attributes.d.ts create mode 100644 test/type/user-profile.test-d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d3594bb4..4c0cf1f61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ ### Bug Fixes -- [#329](https://github.com/okta/okta-sdk-nodejs/pull/360) Fixes path and type signature issues for MemoryStore. - +- [#360](https://github.com/okta/okta-sdk-nodejs/pull/360) Fixes path and type signature issues for MemoryStore. +- [#365](https://github.com/okta/okta-sdk-nodejs/pull/365) Adds support for custom attributes in UserProfile and GroupProfile # 6.5.0 diff --git a/src/types/custom-attributes.d.ts b/src/types/custom-attributes.d.ts new file mode 100644 index 000000000..112e2f72d --- /dev/null +++ b/src/types/custom-attributes.d.ts @@ -0,0 +1,18 @@ +/*! + * Copyright (c) 2017-present, Okta, Inc. and/or its affiliates. All rights reserved. + * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and limitations under the License. + */ + + +type CustomAttributeValue = boolean | number | string; + +export { + CustomAttributeValue +}; diff --git a/src/types/models/GroupProfile.d.ts b/src/types/models/GroupProfile.d.ts index b52811ff7..309f9bf9f 100644 --- a/src/types/models/GroupProfile.d.ts +++ b/src/types/models/GroupProfile.d.ts @@ -14,6 +14,7 @@ /* THIS FILE IS AUTO-GENERATED - SEE CONTRIBUTOR DOCUMENTATION */ import { Resource } from '../resource'; +import { CustomAttributeValue } from '../custom-attributes'; import { Client } from '../client'; import { OptionalKnownProperties } from '../optional-known-properties-type'; @@ -23,6 +24,7 @@ declare class GroupProfile extends Resource { description: string; name: string; + [key: string]: CustomAttributeValue | CustomAttributeValue[] } diff --git a/src/types/models/InlineHookPayload.d.ts b/src/types/models/InlineHookPayload.d.ts index ac0224e4f..3e1c6b835 100644 --- a/src/types/models/InlineHookPayload.d.ts +++ b/src/types/models/InlineHookPayload.d.ts @@ -14,12 +14,14 @@ /* THIS FILE IS AUTO-GENERATED - SEE CONTRIBUTOR DOCUMENTATION */ import { Resource } from '../resource'; +import { CustomAttributeValue } from '../custom-attributes'; import { Client } from '../client'; declare class InlineHookPayload extends Resource { constructor(resourceJson: Record, client: Client); + [key: string]: CustomAttributeValue | CustomAttributeValue[] } diff --git a/src/types/models/SmsTemplateTranslations.d.ts b/src/types/models/SmsTemplateTranslations.d.ts index 84140b6f5..8073bf15d 100644 --- a/src/types/models/SmsTemplateTranslations.d.ts +++ b/src/types/models/SmsTemplateTranslations.d.ts @@ -14,12 +14,14 @@ /* THIS FILE IS AUTO-GENERATED - SEE CONTRIBUTOR DOCUMENTATION */ import { Resource } from '../resource'; +import { CustomAttributeValue } from '../custom-attributes'; import { Client } from '../client'; declare class SmsTemplateTranslations extends Resource { constructor(resourceJson: Record, client: Client); + [key: string]: CustomAttributeValue | CustomAttributeValue[] } diff --git a/src/types/models/UserProfile.d.ts b/src/types/models/UserProfile.d.ts index 1cf57f95c..4b3291abe 100644 --- a/src/types/models/UserProfile.d.ts +++ b/src/types/models/UserProfile.d.ts @@ -14,6 +14,7 @@ /* THIS FILE IS AUTO-GENERATED - SEE CONTRIBUTOR DOCUMENTATION */ import { Resource } from '../resource'; +import { CustomAttributeValue } from '../custom-attributes'; import { Client } from '../client'; import { OptionalKnownProperties } from '../optional-known-properties-type'; @@ -52,6 +53,7 @@ declare class UserProfile extends Resource { title: string; userType: string; zipCode: string; + [key: string]: CustomAttributeValue | CustomAttributeValue[] } diff --git a/templates/model.d.ts.hbs b/templates/model.d.ts.hbs index 75105947d..70627cd3c 100644 --- a/templates/model.d.ts.hbs +++ b/templates/model.d.ts.hbs @@ -6,6 +6,9 @@ import { {{extends}} } from './{{extends}}'; {{else}} import { Resource } from '../resource'; {{/if}} +{{#if this.isExtensible}} +import { CustomAttributeValue } from '../custom-attributes'; +{{/if}} import { Client } from '../client'; {{#if (shouldGenerateOptionsType modelName)}} {{#if properties.length}} @@ -36,6 +39,9 @@ declare class {{modelName}} extends Resource { {{/if}} {{/unless}} {{/each}} +{{#if this.isExtensible}} + [key: string]: CustomAttributeValue | CustomAttributeValue[] +{{/if}} {{#each crud}} {{#if (eq alias 'update')}} diff --git a/test/type/user-profile.test-d.ts b/test/type/user-profile.test-d.ts new file mode 100644 index 000000000..122a9c83b --- /dev/null +++ b/test/type/user-profile.test-d.ts @@ -0,0 +1,10 @@ +import { expectType } from 'tsd'; + +import { Client } from '../../src/types/client'; +import { CustomAttributeValue } from '../../src/types/custom-attributes'; +import { UserProfile } from './../../src/types/models/UserProfile.d'; + +const client = new Client(); +const userProfile = new UserProfile({}, client); +expectType(userProfile.customAttribute); +expectType(userProfile.costCenter); diff --git a/yarn.lock b/yarn.lock index deb53581a..382f4aa3b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4799,4 +4799,4 @@ z-schema@^4.2.2: lodash.isequal "^4.5.0" validator "^13.6.0" optionalDependencies: - commander "^2.7.1" + commander "^2.7.1" \ No newline at end of file