Skip to content

Commit 4bc6662

Browse files
authored
Merge pull request #129 from Space-DF/feat/implement-api-get-org-feature
feat: implement api get org feature
2 parents 3308a1a + efc38b9 commit 4bc6662

5 files changed

Lines changed: 176 additions & 0 deletions

File tree

api.doc.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [Trip](#trip)
2828
- [Telemetry](#telemetry)
2929
- [Custom Domains](#custom-domains)
30+
- [Plans](#plans)
3031

3132
# Auth
3233

@@ -4625,3 +4626,119 @@ console.log(response.org_name);
46254626
```
46264627

46274628
</details>
4629+
4630+
---
4631+
4632+
# Plans
4633+
4634+
## Overview
4635+
4636+
The `Plans` class provides methods for retrieving subscription plans, including their pricing items, features, and support entitlements.
4637+
4638+
## Types
4639+
4640+
### PlanCode
4641+
4642+
```typescript
4643+
type PlanCode = 'free' | 'pro';
4644+
```
4645+
4646+
### BillingCycle
4647+
4648+
```typescript
4649+
type BillingCycle = 'monthly' | 'yearly';
4650+
```
4651+
4652+
### FeatureValueType
4653+
4654+
```typescript
4655+
type FeatureValueType = 'limit' | 'boolean' | 'quota';
4656+
```
4657+
4658+
### Plan
4659+
4660+
```typescript
4661+
interface Plan {
4662+
id: string; // Unique identifier of the plan
4663+
name: string; // Human-readable plan name (e.g. "Free")
4664+
code: PlanCode; // Machine-readable plan code (e.g. "free")
4665+
description: string; // Description of the plan
4666+
plan_items: PlanItem[]; // Pricing options for each billing cycle
4667+
is_current_plan: boolean; // Whether this is the caller's current plan
4668+
created_at: string; // Creation timestamp (ISO 8601 format)
4669+
updated_at: string; // Last update timestamp (ISO 8601 format)
4670+
features: PlanFeature[]; // Feature entitlements for the plan
4671+
support: PlanFeature[]; // Support entitlements for the plan
4672+
}
4673+
```
4674+
4675+
### PlanItem
4676+
4677+
```typescript
4678+
interface PlanItem {
4679+
id: string; // Unique identifier of the plan item
4680+
price: string; // Price as a decimal string (e.g. "0.00")
4681+
icon: string; // Icon reference for the plan item
4682+
currency: string; // Currency code (e.g. "USD")
4683+
discount: number; // Discount applied to the price
4684+
billing_cycle: BillingCycle; // Billing cycle for this item
4685+
is_active: boolean; // Whether this item is currently active
4686+
created_at: string; // Creation timestamp (ISO 8601 format)
4687+
updated_at: string; // Last update timestamp (ISO 8601 format)
4688+
}
4689+
```
4690+
4691+
### PlanFeature
4692+
4693+
```typescript
4694+
interface PlanFeature {
4695+
id: string; // Unique identifier of the plan feature
4696+
feature: Feature; // The underlying feature definition
4697+
enabled: boolean; // Whether the feature is enabled for the plan
4698+
limit_value: number | null; // Numeric limit/quota, or null for boolean features
4699+
metadata: Record<string, unknown>; // Additional feature metadata
4700+
}
4701+
```
4702+
4703+
### Feature
4704+
4705+
```typescript
4706+
interface Feature {
4707+
id: string; // Unique identifier of the feature
4708+
code: string; // Machine-readable feature code (e.g. "device.max_count")
4709+
name: string; // Human-readable feature name
4710+
description: string; // Description of the feature
4711+
value_type: FeatureValueType; // How the feature's value is interpreted
4712+
}
4713+
```
4714+
4715+
## Methods
4716+
4717+
<details>
4718+
<summary><strong>retrieve</strong></summary>
4719+
4720+
Retrieve a plan by its code.
4721+
4722+
**Signature:**
4723+
4724+
```typescript
4725+
retrieve(plan: PlanCode, options?: Core.RequestOptions): Core.APIPromise<Plan>
4726+
```
4727+
4728+
**Parameters:**
4729+
4730+
- `plan` _(PlanCode)_: The plan code identifying the plan (`'free'` or `'pro'`).
4731+
- `options` _(Core.RequestOptions, optional)_: Additional request options.
4732+
4733+
**Returns:** `Promise<Plan>`
4734+
4735+
**Example:**
4736+
4737+
```typescript
4738+
const plan = await client.plans.retrieve('free');
4739+
console.log(plan.name);
4740+
console.log(plan.is_current_plan);
4741+
console.log(plan.features.map((f) => f.feature.code));
4742+
```
4743+
4744+
</details>

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export class SpaceDFSDK extends Core.APIClient {
151151
organizations: API.Organizations = new API.Organizations(this);
152152
telemetry: API.Telemetry = new API.Telemetry(this);
153153
customDomains: API.CustomDomain = new API.CustomDomain(this);
154+
plans: API.Plans = new API.Plans(this);
154155

155156
protected override defaultQuery(): Core.DefaultQuery | undefined {
156157
return this._options.defaultQuery;

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from './device/index';
1111
export * from './organizations/index';
1212
export * from './telemetry/index';
1313
export * from './custom-domains/index';
14+
export * from './plans/index';

src/resources/plans/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './plans';

src/resources/plans/plans.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as Core from '../../core';
2+
import { APIResource } from '../../resource';
3+
4+
export class Plans extends APIResource {
5+
retrieve(plan: PlanCode, options?: Core.RequestOptions): Core.APIPromise<Plan> {
6+
Core.ensurePresent(plan);
7+
return this._client.get(`/plans/${plan}`, options);
8+
}
9+
}
10+
11+
export type PlanCode = 'free' | 'pro';
12+
13+
export type BillingCycle = 'monthly' | 'yearly';
14+
15+
export type FeatureValueType = 'limit' | 'boolean' | 'quota';
16+
17+
export interface Plan {
18+
id: string;
19+
name: string;
20+
code: PlanCode;
21+
description: string;
22+
plan_items: PlanItem[];
23+
is_current_plan: boolean;
24+
created_at: string;
25+
updated_at: string;
26+
features: PlanFeature[];
27+
support: PlanFeature[];
28+
}
29+
30+
export interface PlanItem {
31+
id: string;
32+
price: string;
33+
icon: string;
34+
currency: string;
35+
discount: number;
36+
billing_cycle: BillingCycle;
37+
is_active: boolean;
38+
created_at: string;
39+
updated_at: string;
40+
}
41+
42+
export interface PlanFeature {
43+
id: string;
44+
feature: Feature;
45+
enabled: boolean;
46+
limit_value: number | null;
47+
metadata: Record<string, unknown>;
48+
}
49+
50+
export interface Feature {
51+
id: string;
52+
code: string;
53+
name: string;
54+
description: string;
55+
value_type: FeatureValueType;
56+
}

0 commit comments

Comments
 (0)