Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion .sdk.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "88c7735c-a5b9-4bd6-aac7-a4e1dbdd3200",
"id": "a3774c17-32bb-4640-bcac-f894d270aca5",
"tracked_paths": [
{
"editable": true,
Expand Down Expand Up @@ -49,6 +49,22 @@
"editable": true,
"path": "src/resources/v1/README.md"
},
{
"editable": true,
"path": "src/resources/v1/account/README.md"
},
{
"editable": true,
"path": "src/resources/v1/account/index.ts"
},
{
"editable": false,
"path": "src/resources/v1/account/request-types.ts"
},
{
"editable": true,
"path": "src/resources/v1/account/resource-client.ts"
},
{
"editable": true,
"path": "src/resources/v1/ai-clothes-changer/README.md"
Expand Down Expand Up @@ -593,6 +609,34 @@
"editable": true,
"path": "src/types/index.ts"
},
{
"editable": false,
"path": "src/types/v1-account-list-response-subscription-billing-interval-enum.ts"
},
{
"editable": false,
"path": "src/types/v1-account-list-response-subscription-discount.ts"
},
{
"editable": false,
"path": "src/types/v1-account-list-response-subscription-price.ts"
},
{
"editable": false,
"path": "src/types/v1-account-list-response-subscription-status-enum.ts"
},
{
"editable": false,
"path": "src/types/v1-account-list-response-subscription.ts"
},
{
"editable": false,
"path": "src/types/v1-account-list-response-tier-enum.ts"
},
{
"editable": false,
"path": "src/types/v1-account-list-response.ts"
},
{
"editable": false,
"path": "src/types/v1-ai-clothes-changer-create-body-assets-garment-type-enum.ts"
Expand Down Expand Up @@ -1285,6 +1329,10 @@
"editable": false,
"path": "src/types/v1-video-to-video-create-response.ts"
},
{
"editable": false,
"path": "test/v1-account.test.ts"
},
{
"editable": false,
"path": "test/v1-ai-clothes-changer.test.ts"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ Valid values are: `none`, `error`, `warn`, `info`, `debug` (case insensitive). I

## Module Documentation and Snippets

### [v1.account](src/resources/v1/account/README.md)

- [list](src/resources/v1/account/README.md#list) - Get account details

### [v1.aiClothesChanger](src/resources/v1/ai-clothes-changer/README.md)

- [create](src/resources/v1/ai-clothes-changer/README.md#create) - AI Clothes Changer
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magic-hour",
"version": "0.74.1",
"version": "0.75.0",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
1 change: 1 addition & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Submodules

- [account](resources/v1/account/README.md) - account
- [ai-clothes-changer](resources/v1/ai-clothes-changer/README.md) - ai-clothes-changer
- [ai-face-editor](resources/v1/ai-face-editor/README.md) - ai-face-editor
- [ai-gif-generator](resources/v1/ai-gif-generator/README.md) - ai-gif-generator
Expand Down
2 changes: 1 addition & 1 deletion src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum Environment {
Environment = "https://api.magichour.ai",
MockServer = "https://api.sideko.dev/v1/mock/magichour/magic-hour/0.78.1",
MockServer = "https://api.sideko.dev/v1/mock/magichour/magic-hour/0.79.0",
}
1 change: 1 addition & 0 deletions src/resources/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Submodules

- [account](account/README.md) - account
- [ai-clothes-changer](ai-clothes-changer/README.md) - ai-clothes-changer
- [ai-face-editor](ai-face-editor/README.md) - ai-face-editor
- [ai-gif-generator](ai-gif-generator/README.md) - ai-gif-generator
Expand Down
30 changes: 30 additions & 0 deletions src/resources/v1/account/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# v1.account

## Module Functions

### Get account details <a name="list"></a>

Get the current credit balance and subscription details of the account that owns the API key.

**API Endpoint**: `GET /v1/account`

#### Example Snippet

```typescript
import { Client } from "magic-hour";

const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.account.list();
```

#### Response

##### Type

[V1AccountListResponse](/src/types/v1-account-list-response.ts)

##### Example

```typescript
{"credits": 12500, "email": "user@example.com", "id": "cuid-example", "subscription": {"billingInterval": "month", "cancelAtPeriodEnd": false, "currentPeriodEnd": "2026-10-01T00:00:00.000Z", "discount": {"amountOff": 123, "percentOff": 20.0}, "name": "Pro", "price": {"amount": 4900, "currency": "usd"}, "status": "active"}, "tier": "pro"}
```
1 change: 1 addition & 0 deletions src/resources/v1/account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AccountClient } from "./resource-client";
33 changes: 33 additions & 0 deletions src/resources/v1/account/resource-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
ApiPromise,
CoreClient,
CoreResourceClient,
RequestOptions,
ResourceClientOptions,
} from "make-api-request-js";

import * as types from "magic-hour/types";
import { Schemas$V1AccountListResponse } from "magic-hour/types/v1-account-list-response";

export class AccountClient extends CoreResourceClient {
constructor(coreClient: CoreClient, opts: ResourceClientOptions) {
super(coreClient, opts);
}

/**
* Get account details
*
* Get the current credit balance and subscription details of the account that owns the API key.
*
* GET /v1/account
*/
list(opts?: RequestOptions): ApiPromise<types.V1AccountListResponse> {
return this._client.makeRequest({
method: "get",
path: "/v1/account",
auth: ["bearerAuth"],
responseSchema: Schemas$V1AccountListResponse.in,
opts,
});
}
}
1 change: 1 addition & 0 deletions src/resources/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * as account from "./account";
export * as aiClothesChanger from "./ai-clothes-changer";
export * as aiFaceEditor from "./ai-face-editor";
export * as aiGifGenerator from "./ai-gif-generator";
Expand Down
13 changes: 13 additions & 0 deletions src/resources/v1/resource-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ResourceClientOptions,
} from "make-api-request-js";

import { AccountClient } from "magic-hour/resources/v1/account";
import { AiClothesChangerClient } from "magic-hour/resources/v1/ai-clothes-changer";
import { AiFaceEditorClient } from "magic-hour/resources/v1/ai-face-editor";
import { AiGifGeneratorClient } from "magic-hour/resources/v1/ai-gif-generator";
Expand Down Expand Up @@ -38,6 +39,7 @@ import { VideoProjectsClient } from "magic-hour/resources/v1/video-projects";
import { VideoToVideoClient } from "magic-hour/resources/v1/video-to-video";

export class V1Client extends CoreResourceClient {
private _accountLazy?: AccountClient; // lazy-loading cache
private _characterReplaceLazy?: CharacterReplaceClient; // lazy-loading cache
private _aiVideoEditorLazy?: AiVideoEditorClient; // lazy-loading cache
private _audioToVideoLazy?: AudioToVideoClient; // lazy-loading cache
Expand Down Expand Up @@ -75,6 +77,7 @@ export class V1Client extends CoreResourceClient {
constructor(coreClient: CoreClient, opts: ResourceClientOptions) {
super(coreClient, opts);
if (this._opts.lazyLoad === false) {
this.account;
this.aiClothesChanger;
this.aiFaceEditor;
this.aiGifGenerator;
Expand Down Expand Up @@ -455,4 +458,14 @@ export class V1Client extends CoreResourceClient {
))
);
}

get account(): AccountClient {
return (
this._accountLazy ??
(this._accountLazy = new (require("./account").AccountClient)(
this._client,
this._opts,
))
);
}
}
7 changes: 7 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export { V1AccountListResponse } from "./v1-account-list-response";
export { V1AccountListResponseSubscription } from "./v1-account-list-response-subscription";
export { V1AccountListResponseSubscriptionBillingIntervalEnum } from "./v1-account-list-response-subscription-billing-interval-enum";
export { V1AccountListResponseSubscriptionDiscount } from "./v1-account-list-response-subscription-discount";
export { V1AccountListResponseSubscriptionPrice } from "./v1-account-list-response-subscription-price";
export { V1AccountListResponseSubscriptionStatusEnum } from "./v1-account-list-response-subscription-status-enum";
export { V1AccountListResponseTierEnum } from "./v1-account-list-response-tier-enum";
export { V1AiClothesChangerCreateBody } from "./v1-ai-clothes-changer-create-body";
export { V1AiClothesChangerCreateBodyAssets } from "./v1-ai-clothes-changer-create-body-assets";
export { V1AiClothesChangerCreateBodyAssetsGarmentTypeEnum } from "./v1-ai-clothes-changer-create-body-assets-garment-type-enum";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* How often the subscription is billed. `null` if unknown.
*/
export type V1AccountListResponseSubscriptionBillingIntervalEnum =
| "month"
| "year";
70 changes: 70 additions & 0 deletions src/types/v1-account-list-response-subscription-discount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { zodTransform } from "make-api-request-js";
import * as z from "zod";

/**
* Discount applied to the subscription. `null` if no discount is applied.
*/
export type V1AccountListResponseSubscriptionDiscount = {
/**
* Fixed amount taken off `price.amount` each billing interval, in the smallest unit of the currency. `null` if the discount is a percentage.
*/
amountOff: number | null;
/**
* Percentage taken off `price.amount` each billing interval. `null` if the discount is a fixed amount.
*/
percentOff: number | null;
};

/**
* @internal
* V1AccountListResponseSubscriptionDiscount without any key transformation, this is what
* we expect to come in as network data
*/
export type External$V1AccountListResponseSubscriptionDiscount = {
amount_off: number | null;
percent_off: number | null;
};

/**
* Takes network data, validates it, and transforms keys to match typescript object V1AccountListResponseSubscriptionDiscount
*/
const SchemaIn$V1AccountListResponseSubscriptionDiscount: z.ZodType<
V1AccountListResponseSubscriptionDiscount, // output type of this zod object
z.ZodTypeDef,
unknown
> = z
.object({
amount_off: z.number().int().nullable(),
percent_off: z.number().nullable(),
})
.transform((obj) => {
return zodTransform(obj, {
amount_off: "amountOff",
percent_off: "percentOff",
});
});

/**
* @internal
* Takes typescript data, validates it, and maps keys to match the expected external object External$V1AccountListResponseSubscriptionDiscount
*/
const SchemaOut$V1AccountListResponseSubscriptionDiscount: z.ZodType<
External$V1AccountListResponseSubscriptionDiscount, // output type of this zod object
z.ZodTypeDef,
V1AccountListResponseSubscriptionDiscount // the object to be transformed
> = z
.object({
amountOff: z.number().int().nullable(),
percentOff: z.number().nullable(),
})
.transform((obj) => {
return zodTransform(obj, {
amountOff: "amount_off",
percentOff: "percent_off",
});
});

export const Schemas$V1AccountListResponseSubscriptionDiscount = {
in: SchemaIn$V1AccountListResponseSubscriptionDiscount,
out: SchemaOut$V1AccountListResponseSubscriptionDiscount,
};
Loading
Loading