# Configuration

{% hint style="warning" %}
Sample code uses ES6 language features such as arrow functions and promises. For compatibility with IE11, code written with these features must be either transpiled using tools like Babel or refactored accordingly using callbacks.
{% endhint %}

## Introduction

In order to use the JS-SDK, the library must be initialised with an api-key. The api-key is a key received upon subscription. The JS-SDK is a client library for web based consumers. As a reminder, the T1C can be used from a native applications context using a native client, or addressing directly the T1C interface.\
In order to work with an api-key in a browser context, 2 type of consumers can be distinguished:

* SPA (Single Page Application) integration: this is a web application without any back-end
* Web Application integration: this is a web application with a back-end implementation

For an SPA, an api-key (thus the access token to the Distribution Service) is considered **unsafe** in a browser context. For SPA's, Trust1Team configures extra security measures on infrastructure level. A mutual authentication is required and additional policies are applied (IP restriction policy, ...).

The api-key must be translated into an JWT token in order to enable communication with the T1C.

## Initialise the client library

To initialise the JavaScript client library, the library must be loaded into your HTML page:

```markup
<script src="../T1CSdk.js" charset="utf-8"></script>
```

Once loaded, the script will expose a GCLLib global. This global will allow you to create a `GCLConfig`:

The `GCLConfigOptions` object will allow you to specify and/or override the configuration to be used. Configuration options can be found in the `Configuration Options` below. You can create a `GCLConfigOptions` as follows:

```javascript
var configoptions = new T1CSdk.T1CConfigOptions(
            environment.t1cApiUrl,
            environment.t1cApiPort,
            environment.t1cApiUrl,
            environment.t1cApiPort,
            environment.jwt
        );
        
config = new T1CSdk.T1CConfig(configoptions);
```

Now that we have a configuration, we can initialise the client library. The following example creates a Promise that will resolve with an instance of a `T1CClient`:

```javascript
T1CSdk.T1CClient.initialize(config).then(res => {
        client = res;
        console.log("Client config: ", client.localConfig)
        core = client.core();
    }, err => {});
```


---

# 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://t1t.gitbook.io/t1c-js-guide-v3/v3.3.0-1/core/configuration.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.
