Skip to content

Commit

Permalink
feat: Include raw JSON in Typescript (box/box-codegen#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build committed Oct 17, 2024
1 parent 2de75a2 commit 7446e4e
Show file tree
Hide file tree
Showing 269 changed files with 1,961 additions and 284 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "f5d1f42", "specHash": "f0c2ce4", "version": "1.6.0" }
{ "engineHash": "83d735e", "specHash": "f0c2ce4", "version": "1.6.0" }
12 changes: 11 additions & 1 deletion docs/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,17 @@ This operation is performed by calling function `createAiExtractStructured`.
See the endpoint docs at
[API Reference](https://developer.box.com/reference/post-ai-extract-structured/).

_Currently we don't have an example for calling `createAiExtractStructured` in integration tests_
<!-- sample post_ai_extract_structured -->

```ts
await client.ai.createAiExtractStructured({
metadataTemplate: {
templateKey: templateKey,
scope: 'enterprise',
} satisfies AiExtractStructuredMetadataTemplateField,
items: [new AiItemBase({ id: file.id })],
} satisfies AiExtractStructured);
```

### Arguments

Expand Down
50 changes: 18 additions & 32 deletions docs/metadataTemplates.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ See the endpoint docs at
```ts
await client.metadataTemplates.deleteMetadataTemplate(
'enterprise' as DeleteMetadataTemplateScope,
templateKey
template.templateKey!
);
```

Expand Down Expand Up @@ -273,48 +273,34 @@ await client.metadataTemplates.createMetadataTemplate({
templateKey: templateKey,
fields: [
{
key: 'firstName',
displayName: 'First name',
description: 'Person first name',
type: 'string' as CreateMetadataTemplateRequestBodyFieldsTypeField,
key: 'name',
displayName: 'name',
} satisfies CreateMetadataTemplateRequestBodyFieldsField,
{
type: 'float' as CreateMetadataTemplateRequestBodyFieldsTypeField,
key: 'age',
displayName: 'age',
key: 'lastName',
displayName: 'Last name',
description: 'Person last name',
type: 'string' as CreateMetadataTemplateRequestBodyFieldsTypeField,
} satisfies CreateMetadataTemplateRequestBodyFieldsField,
{
key: 'dateOfBirth',
displayName: 'Birth date',
description: 'Person date of birth',
type: 'date' as CreateMetadataTemplateRequestBodyFieldsTypeField,
key: 'birthDate',
displayName: 'birthDate',
} satisfies CreateMetadataTemplateRequestBodyFieldsField,
{
type: 'enum' as CreateMetadataTemplateRequestBodyFieldsTypeField,
key: 'countryCode',
displayName: 'countryCode',
options: [
{
key: 'US',
} satisfies CreateMetadataTemplateRequestBodyFieldsOptionsField,
{
key: 'CA',
} satisfies CreateMetadataTemplateRequestBodyFieldsOptionsField,
],
key: 'age',
displayName: 'Age',
description: 'Person age',
type: 'float' as CreateMetadataTemplateRequestBodyFieldsTypeField,
} satisfies CreateMetadataTemplateRequestBodyFieldsField,
{
key: 'hobby',
displayName: 'Hobby',
description: 'Person hobby',
type: 'multiSelect' as CreateMetadataTemplateRequestBodyFieldsTypeField,
key: 'sports',
displayName: 'sports',
options: [
{
key: 'basketball',
} satisfies CreateMetadataTemplateRequestBodyFieldsOptionsField,
{
key: 'football',
} satisfies CreateMetadataTemplateRequestBodyFieldsOptionsField,
{
key: 'tennis',
} satisfies CreateMetadataTemplateRequestBodyFieldsOptionsField,
],
} satisfies CreateMetadataTemplateRequestBodyFieldsField,
],
} satisfies CreateMetadataTemplateRequestBody);
Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/box/jwtAuth.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface JwtConfigAppSettingsAppAuth {
/**
* Passphrase */
readonly passphrase: string;
readonly rawData?: SerializedData;
}
export interface JwtConfigAppSettings {
/**
Expand All @@ -46,6 +47,7 @@ export interface JwtConfigAppSettings {
/**
* App auth settings */
readonly appAuth: JwtConfigAppSettingsAppAuth;
readonly rawData?: SerializedData;
}
export interface JwtConfigFile {
/**
Expand All @@ -57,6 +59,7 @@ export interface JwtConfigFile {
/**
* App settings */
readonly boxAppSettings: JwtConfigAppSettings;
readonly rawData?: SerializedData;
}
export class JwtConfig {
/**
Expand Down Expand Up @@ -128,9 +131,10 @@ export class JwtConfig {
configJsonString: string,
tokenStorage?: TokenStorage
): JwtConfig {
const configJson: JwtConfigFile = deserializeJwtConfigFile(
jsonToSerializedData(configJsonString)
);
const configJson: JwtConfigFile = {
...deserializeJwtConfigFile(jsonToSerializedData(configJsonString)),
rawData: jsonToSerializedData(configJsonString),
};
const newConfig: JwtConfig = !(tokenStorage == void 0)
? new JwtConfig({
clientId: configJson.boxAppSettings.clientId,
Expand Down
14 changes: 14 additions & 0 deletions src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,17 @@ export function createAgent(options?: AgentOptions, proxyConfig?: any): Agent {
export async function delayInSeconds(seconds: number): Promise<void> {
return await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
}

/**
* Get value from object raw data.
*
* @param obj Object with raw data from which to get the value.
* @param key Key of the value to get.
* @returns Value from object raw data.
*/
export function getValueFromObjectRawData(obj: any, key: string): any {
if (obj && typeof obj === 'object' && obj.rawData) {
return obj.rawData[key];
}
return undefined;
}
29 changes: 22 additions & 7 deletions src/managers/ai.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ export class AiManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeAiResponseFull(response.data);
return {
...deserializeAiResponseFull(response.data),
rawData: response.data,
};
}
/**
* Sends an AI request to supported Large Language Models (LLMs) and returns generated text based on the provided prompt.
Expand Down Expand Up @@ -380,7 +383,10 @@ export class AiManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeAiResponse(response.data);
return {
...deserializeAiResponse(response.data),
rawData: response.data,
};
}
/**
* Get the AI agent default config
Expand Down Expand Up @@ -422,9 +428,12 @@ export class AiManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeAiAgentAskOrAiAgentExtractOrAiAgentExtractStructuredOrAiAgentTextGen(
response.data
);
return {
...deserializeAiAgentAskOrAiAgentExtractOrAiAgentExtractStructuredOrAiAgentTextGen(
response.data
),
rawData: response.data,
};
}
/**
* Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of key-value pairs.
Expand Down Expand Up @@ -460,7 +469,10 @@ export class AiManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeAiResponse(response.data);
return {
...deserializeAiResponse(response.data),
rawData: response.data,
};
}
/**
* Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as a set of key-value pairs.
Expand Down Expand Up @@ -499,7 +511,10 @@ export class AiManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeAiExtractResponse(response.data);
return {
...deserializeAiExtractResponse(response.data),
rawData: response.data,
};
}
}
export interface AiManagerInput {
Expand Down
10 changes: 8 additions & 2 deletions src/managers/appItemAssociations.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ export class AppItemAssociationsManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeAppItemAssociations(response.data);
return {
...deserializeAppItemAssociations(response.data),
rawData: response.data,
};
}
/**
* **This is a beta feature, which means that its availability might be limited.**
Expand Down Expand Up @@ -299,7 +302,10 @@ export class AppItemAssociationsManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeAppItemAssociations(response.data);
return {
...deserializeAppItemAssociations(response.data),
rawData: response.data,
};
}
}
export interface AppItemAssociationsManagerInput {
Expand Down
10 changes: 8 additions & 2 deletions src/managers/authorization.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ export class AuthorizationManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeAccessToken(response.data);
return {
...deserializeAccessToken(response.data),
rawData: response.data,
};
}
/**
* Refresh an Access Token using its client ID, secret, and refresh token.
Expand Down Expand Up @@ -406,7 +409,10 @@ export class AuthorizationManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeAccessToken(response.data);
return {
...deserializeAccessToken(response.data),
rawData: response.data,
};
}
/**
* Revoke an active Access Token, effectively logging a user out
Expand Down
5 changes: 4 additions & 1 deletion src/managers/avatars.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ export class AvatarsManager {
networkSession: this.networkSession,
cancellationToken: cancellationToken,
} satisfies FetchOptions)) as FetchResponse;
return deserializeUserAvatar(response.data);
return {
...deserializeUserAvatar(response.data),
rawData: response.data,
};
}
/**
* Removes an existing user avatar.
Expand Down
Loading

0 comments on commit 7446e4e

Please sign in to comment.