# Bundle Manager

### BundleManager

Provides a high-level interface for managing bundle licenses, including local bundle licenses. The BundleManager is required to work with local bundle license files. This class can share the same license file with the LicenseManager, as both classes are designed to not overwrite each other's data.

Typescript definitions are provided for the arguments and return types of the class methods.

To import the BundleManager class use:

```javascript
const { BundleManager } = require('@licensespring/node-sdk');
```

To create an instance:

```javascript
const bundleManager = new BundleManager({
  apiKey: '12345678-4bfe-4e3a-8737-757004d6294c',
  sharedKey: 'eYuHrlajvIVTiSFIXpxpKhw78f4Ewy-00-12345678',
  appName: 'js-sdk-test-1',
  appVersion: '0.0.1',
  productCode: 'bkp',
  /** NOTE: the following properties are set to their default values by the SDK and can be overriden manually: */
  // apiPath: 'http://api.dev.licensespring.com/api/v4',
  // publicKey: '...',
});
```

The constructor takes the a single argument of the following type:

```typescript
{
  /** your Licensespring API key */
  apiKey: string,
  /** your Licensespring API Shared key **/
  sharedKey: string,
  /** custom name for your application */
  appName: string,
  /** custom version string for your application */
  appVersion: string,
  /** your product short code */
  productCode: string,
  /** your Air Gap Activation key (optional) */
  airGapKey?: string,
  /** override for License API url (default is https://api.licensespring.com/api/v4/) **/
  apiPath?: string,
  /** override for License API public key (default is pub key for api.licensespring.com) **/
  publicKey?: string,
  /** override for License File filename (default is "License") */
  filename?: string,
  /** override for License File path (default is current directory) */
  filePath?: string,
  /** override for License File encryption key */
  fileKey?: string,
  /** override for license grace period duration in hours (default is 24) */
  gracePeriod?: number,
  /** override for License File guard file (default is false) */
  isGuardFileEnabled?: boolean,
  /** override for Hardware ID calculation method (default is 0, for more info see "Hardware ID" section) */
  hardwareIDMethod?: number,
  /** a custom provided Hardware ID (overrides HWID calculation) */
  hardwareID?: string,
}
```

### Methods

Methods listed here which take a license payload are the similar to corresponding methods in the License API class, except that `product` and `hardware_id` do not have to be specified in the payload as they are provided by the Bundle Manager object.

#### Check Bundle License

See: [**Check Bundle**](/license-api/license-check/check-bundle.md)

```typescript
checkBundle(
  payload: CheckBundlePayload, 
  includeExpiredFeatures: boolean = false
): Promise<CheckLicenseResponse[]>

type CheckLicensePayload = ({
  username: string;
} | {
  license_key: string;
}) & {
  env: string | undefined;
  license_id: number | undefined;
  sdk_ver: string | undefined;
  app_ver: string | undefined;
  hostname: string | undefined;
  os_hostname: string | undefined;
  ip_local: string | undefined;
  mac_address: string | undefined;
  ip: string | undefined;
  os_ver: string | undefined;
  channel: string | undefined;
};

type CheckLicenseResponse = {
  id: number,
  allow_grace_period: boolean,
  allow_overages: boolean,
  allow_unlimited_activations: boolean,
  allow_offline_activation: boolean,
  can_borrow: boolean,
  custom_fields: CustomField[],
  customer: CustomerResponse,
  enable_maintenance_period: boolean,
  floating_timeout: number,
  floating_users?: number,
  grace_period: number | null,
  is_air_gapped: boolean,
  is_floating: boolean,
  is_floating_cloud: boolean,
  is_hardware_key_auth: boolean,
  license_key: string | undefined,
  license_template_id?: number,
  maintenance_period: string | null,
  max_activations: number,
  max_borrow_time: number,
  max_license_users?: number,
  max_overages: number,
  max_transfers?: number,
  metadata: JSONObjectRequired,
  metadata_string?: string,
  order_store_id?: string,
  prevent_vm: boolean,
  company: {
    id: number,
  },
  product_details?: ProductDetailsResponse,
  product_features: FeatureResponse[],
  start_date: string | null,
  times_activated: number,
  transfer_count: number,
  validity_period: string | null,
  is_trial: boolean,
  trial_days?: number,
  user?: LicenseUserResponse,
  license_type: LicenseTypes,
  allow_negative_consumptions?: boolean,
  allow_unlimited_consumptions?: boolean,
  consumption_period?: 'daily' | 'weekly' | 'monthly' | 'annually' | null,
  max_consumptions?: number,
  reset_consumption?: boolean,
  total_consumptions?: number,
  borrowed_until: string | null,
  floating_in_use_devices?: number,
  is_borrowed: boolean,
  is_expired: boolean,
  license_active: boolean,
  license_enabled: boolean,
  license_signature: string,
};
```

#### Activate Bundle License Online

See: [**Activate Bundle (Online Method)**](/license-api/license-activation-and-deactivation/activate-bundle-online-method.md)

```typescript
activateBundle(payload: ActivateBundlePayload): Promise<ActivateLicenseResponse[]>

type ActivateBundlePayload = ({ 
  license_key: string; 
} | {
  username: string;
  password: string;
} | {
  code: string;
  customer_account_code: string;
} | {
  id_token: string;
  customer_account_code: string;
}) & {
  variables: { [key: string]: string | number | boolean } | undefined;
};

type ActivateLicenseResponse = {
  id: number,
  allow_grace_period: boolean,
  allow_overages: boolean,
  allow_unlimited_activations: boolean,
  allow_offline_activation: boolean,
  can_borrow: boolean,
  custom_fields: CustomField[],
  customer: CustomerResponse,
  enable_maintenance_period: boolean,
  floating_timeout: number,
  floating_users?: number,
  grace_period: number | null,
  is_air_gapped: boolean,
  is_floating: boolean,
  is_floating_cloud: boolean,
  is_hardware_key_auth: boolean,
  license_key: string | undefined,
  license_template_id?: number,
  maintenance_period: string | null,
  max_activations: number,
  max_borrow_time: number,
  max_license_users?: number,
  max_overages: number,
  max_transfers?: number,
  metadata: JSONObjectRequired,
  metadata_string?: string,
  order_store_id?: string,
  prevent_vm: boolean,
  company: {
    id: number,
  },
  product_details?: ProductDetailsResponse,
  product_features: FeatureResponse[],
  start_date: string | null,
  times_activated: number,
  transfer_count: number,
  validity_period: string | null,
  is_trial: boolean,
  trial_days?: number,
  user?: LicenseUserResponse,
  license_type: LicenseTypes,
  allow_negative_consumptions?: boolean,
  allow_unlimited_consumptions?: boolean,
  consumption_period?: 'daily' | 'weekly' | 'monthly' | 'annually' | null,
  max_consumptions?: number,
  reset_consumption?: boolean,
  total_consumptions?: number,
  request: string,
  active: boolean,
  device_id: number,
  validity_period: string | null,
  is_expired: boolean,
  hardware_id: string,
  username?: string,
  max_license_users?: number,
  is_floating_cloud: boolean,
  floating_in_use?: boolean,
  license_signature: string,
  variables?: ({
    value: string;
    device_id: number;
    variable: string;
    created_at: string | null;
  })[];
};
```

#### Deactivate License Online

See: [**Deactivate Bundle (Online Method)**](/license-api/license-activation-and-deactivation/deactivate-bundle-online-method.md)

```typescript
deactivateBundle(payload: ({  
  username: string;
} | {
  license_key: string;
}): Promise<boolean>
```

#### Activate Bundle License Offline

See: [**Activate Bundle (Offline Method)**](/license-api/license-activation-and-deactivation/activate-bundle-offline-method.md)

```typescript
activateOffline(payload: string): Promise<ActivateOfflineResponse>

type ActivateOfflineResponse = {
  id: number,
  allow_grace_period: boolean,
  allow_overages: boolean,
  allow_unlimited_activations: boolean,
  allow_offline_activation: boolean,
  can_borrow: boolean,
  custom_fields: CustomField[],
  customer: CustomerResponse,
  enable_maintenance_period: boolean,
  floating_timeout: number,
  floating_users?: number,
  grace_period: number | null,
  is_air_gapped: boolean,
  is_floating: boolean,
  is_floating_cloud: boolean,
  is_hardware_key_auth: boolean,
  license_key: string | undefined,
  license_template_id?: number,
  maintenance_period: string | null,
  max_activations: number,
  max_borrow_time: number,
  max_license_users?: number,
  max_overages: number,
  max_transfers?: number,
  metadata: JSONObjectRequired,
  metadata_string?: string,
  order_store_id?: string,
  prevent_vm: boolean,
  company: {
    id: number,
  },
  product_details?: ProductDetailsResponse,
  product_features: FeatureResponse[],
  start_date: string | null,
  times_activated: number,
  transfer_count: number,
  validity_period: string | null,
  is_trial: boolean,
  trial_days?: number,
  user?: LicenseUserResponse,
  license_type: LicenseTypes,
  allow_negative_consumptions?: boolean,
  allow_unlimited_consumptions?: boolean,
  consumption_period?: 'daily' | 'weekly' | 'monthly' | 'annually' | null,
  max_consumptions?: number,
  reset_consumption?: boolean,
  total_consumptions?: number,
  request: string,
  active: boolean,
  device_id: number,
  validity_period: string | null,
  is_expired: boolean,
  hardware_id: string,
  username?: string,
  max_license_users?: number,
  is_floating_cloud: boolean,
  floating_in_use?: boolean,
  license_signature: string,
  variables?: ({
    value: string;
    device_id: number;
    variable: string;
    created_at: string | null;
  })[];
  date: string,
  offline_signature: string,
  license_signature_v2: string,
};
```

#### Deactivate Bundle License Offline

Performs an offline deactivation

```typescript
deactivateOffline(): Promise<boolean>
```

#### Change Password

See: [**Change Password**](/license-api/change-password.md)

```typescript
changePassword(payload: {
    username: string;
    password: string;
    new_password: string;
}): Promise<boolean>
```

#### Get Product Versions

See: [**Get Product Versions**](/license-api/get-product-versions.md)

```typescript
getVersions(payload: GetVersionsPayload): Promise<VersionsResponse>

type GetVersionsPayload = ({
    license_key: string;
} | {
    username: string;
}) & {
    sdk_ver: string | undefined;
    env: string | undefined;
    channel: string | undefined;
};

type VersionsResponse = ({
  version: string | undefined;
  release_date: string | null;
})[];
```

#### Get Product Installation File

See: [**Get Installation File**](/license-api/get-installation-file.md)

```typescript
getInstallationFile(payload: GetInstallationFilePayload): Promise<InstallationFileResponse>

type GetInstallationFilePayload = ({
    license_key: string;
} | {
    username: string;
}) & {
    sdk_ver: string | undefined;
    env: string | undefined;
    channel: string | undefined;
    version: string | undefined;
};

type InstallationFileResponse = {
  id: number;
  version: string | undefined;
  installation_file: string | undefined;
  release_date: string | null;
  hash_md5: string | undefined;
  environment: string;
  eula_link: string | undefined;
  release_notes_link: string | undefined;
  size: string | undefined;
  requires_version: string | undefined;
  channel: string | undefined;
  company: {
    id: number;
  };
};
```

#### Get Single Sign-On URL

See: [**Single Sign On URL**](/license-api/single-sign-on-url.md)

```typescript
getSSOUrl(payload: {
    response_type: 'token' | 'code' | undefined;
    product: string;
    customer_account_code: string;
}): Promise<SSOUrlResponse>

type SSOUrlResponse = {
  url: string;
  openid_configuration: {
    [key: string]: string | number | boolean;
  };
};
```

#### License Utility Methods

The following methods on the BundleManager class take a single argument which is the license object returned from a license activation, a license check or parsed from the license file.

Checks if License is enabled, active and not expired:

```typescript
isValid(license: {
    license_active: boolean,
    license_enabled: boolean,
    validity_period: DateISO8601UTC | null,
  }): boolean
```

Returns days remaining in maintenance period:

```typescript
maintenanceDaysRemaining(license: {
    enable_maintenance_period: boolean
    maintenance_period: string | null,
  }): number
```

Returns days remaining in license validity period:

```typescript
daysRemaining(license: {
    grace_period: number,
    validity_period: DateISO8601UTC | null,
  }): number
```

#### License File

See [**License File**](https://www.npmjs.com/package/@licensespring/node-sdk#license-file)

```typescript
/** Reads and parses the local license file and returns its data as a License object */
loadBundle(): License

/** Verifies the local bundle license file's integrity */
isLicenseFileCorrupted(): boolean

/** Deletes the local bundle license file and guard file */
clearLocalStorage(): void
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.licensespring.com/sdks/node.js-sdk/bundle-manager.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
