@imtbl/sdk 0.28.10-alpha.1 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,3 +27,150 @@ npm install @imtbl/sdk
27
27
  # or
28
28
  yarn add @imtbl/sdk
29
29
  ```
30
+
31
+ ## Changelog
32
+
33
+ ### [0.29.0] - 13-11-2023
34
+
35
+ #### Changed (breaking)
36
+
37
+ ##### The `connectImx` method no longer registers users on Immutable X
38
+
39
+ This method was previously responsible for automatically [registering a user](https://docs.immutable.com/docs/x/how-to-register-users/)
40
+ the first time they connect to Immutable X.
41
+
42
+ ###### Before
43
+
44
+ ```ts
45
+ const passport = new Passport(...);
46
+ const provider = await passport.connectImx();
47
+ ```
48
+
49
+ ###### After
50
+
51
+ Passport now allows you to manage the registration process yourself through the `isRegisteredOffchain` and
52
+ `registerOffchain` functions.
53
+
54
+ This gives you the advantage of potentially displaying a custom UI informing the user that they’re being registered,
55
+ as opposed to the previous experience where the user was waiting until the `connectImx` step completed all the steps.
56
+
57
+ ```ts
58
+ const passport = new Passport(...);
59
+ const provider = await passport.connectImx();
60
+
61
+ if (!await provider.isRegisteredOffchain()) {
62
+ // Potentially inform the user the user that are about to be
63
+ // registered on Immutable X
64
+ await provider.registerOffchain();
65
+ }
66
+
67
+ // The user's wallet is registered, they are now ready to use Immutable X
68
+ const response = await provider.transfer(...);
69
+ ```
70
+
71
+ ##### Passport is now a client-side only module
72
+
73
+ This change is only relevant if you are using server-side rendering (SSR).
74
+
75
+ Passport has a dependency on browser-specific primitives, such as the `window` object, and therefore is intended to be
76
+ used in a client-side environment only.
77
+
78
+ Depending on your framework, you may need to update how you were instantiating the Passport instance to ensure
79
+ this happens on the client.
80
+
81
+ ### [0.28.2] - 30-10-2023
82
+
83
+ #### Added
84
+
85
+ We have added a new `login` method that allows you to authenticate users without necessarily instantiating their wallets.
86
+
87
+ ##### Before
88
+
89
+ Previously, you had to authenticate users as follows:
90
+
91
+ ```ts
92
+ const passport = new Passport(...);
93
+ const provider = await passport.connectImx();
94
+ ```
95
+
96
+ The `connectImx` function performed the following tasks under the hood:
97
+
98
+ - Completed the OIDC authentication flow to log the user in
99
+ - Instantiated their wallet based on their identity
100
+ - Registered the user on the Immutable X ecosystem
101
+
102
+ Although this simple API was simple and convenient, we have decided to decouple it into explicit methods based on customer feedback to provide you with more flexibility.
103
+
104
+ ##### After
105
+
106
+ From now on, you can authenticate users as follows:
107
+
108
+ ```ts
109
+ const passport = new Passport(...);
110
+ const user = await passport.login();
111
+ ```
112
+
113
+ The login method only authenticates the user. This allows you to separate the authentication process from wallet
114
+ instantiation and the registration step, giving you greater control and flexibility in managing user
115
+ authentication within your application.
116
+
117
+ This is especially useful if your application only uses Passport for authentication and does not leverage
118
+ the wallet component.
119
+
120
+ However, if you want to instantiate the wallet, you can do so as follows:
121
+
122
+ ```ts
123
+ const passport = new Passport(...);
124
+ const user = await passport.login(); // Optional
125
+
126
+ const provider = await passport.connectImx();
127
+ ```
128
+
129
+ Depending on your application, you may decide to only log in the user when they click on “Sign in with Passport”
130
+ using `login`, and instantiate the wallet using `connectImx` in the background, ensuring a seamless
131
+ and user-friendly experience.
132
+
133
+ Note that the `connectImx` method will attempt to log the user in automatically if you haven’t explicitly called login
134
+ before connecting to Immutable X.
135
+
136
+ The following code will have the same outcome as the snippet above, but it's important to note that the `Promise`
137
+ returned by `connectImx` will not resolve until the user has successfully logged in and their wallet has been
138
+ instantiated, potentially leading to a less streamlined user experience.
139
+
140
+ ```ts
141
+ const passport = new Passport(...);
142
+ const provider = await passport.connectImx();
143
+ ```
144
+
145
+ Find more information about authenticating users in the [Passport Login documentation](https://docs.immutable.com/docs/x/passport/identity/login#1-trigger-the-login-process).
146
+
147
+ #### Deprecated
148
+
149
+ Following the introduction of the `login` method, we have deprecated the `connectImxSilent` method.
150
+
151
+ This method was previously used for [rehydrating the session of previously authenticated users](https://docs.immutable.com/docs/x/passport/identity/login/#3-maintaining-the-login-status)
152
+ on page reloads.
153
+
154
+ ##### Before
155
+
156
+ ```ts
157
+ // On page load, attempt to re-authenticate the user without propting them to
158
+ // sign in based on their cached session and initialise the wallet.
159
+ const provider = await passport.connectImxSilent();
160
+
161
+ if (!provider) {
162
+ // The user session couldn't be recovered. The user will have to explicitly
163
+ // sign in again by clicking a button that trigger passport.connectImx()
164
+ }
165
+ ```
166
+
167
+ ##### After
168
+ ```ts
169
+ // On page load, attempt to re-authenticate the user without propting them to
170
+ // sign in based on their cached session.
171
+ const user = await passport.login({ useCachedSession: true });
172
+ if (user) {
173
+ // The user session is still valid, we can now initialise the wallet
174
+ const provider = await passport.connectImx();
175
+ }
176
+ ```
@@ -3689,16 +3689,25 @@ declare class ImmutableConfiguration {
3689
3689
  readonly environment: Environment;
3690
3690
  readonly rateLimitingKey?: string;
3691
3691
  readonly apiKey?: string;
3692
- readonly clientAppId?: string;
3692
+ readonly publishableKey?: string;
3693
3693
  constructor(options: {
3694
3694
  environment: Environment;
3695
- rateLimitingKey?: string;
3696
- apiKey?: string;
3697
- clientAppId?: string;
3698
3695
  });
3699
3696
  }
3697
+ type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (T extends {
3698
+ apiKey: 'required';
3699
+ } ? Required<{
3700
+ apiKey: string;
3701
+ }> : {}) & (T extends {
3702
+ publishableKey: 'required';
3703
+ } ? Required<{
3704
+ publishableKey: string;
3705
+ }> : {});
3706
+ type ImmutableConfigurationWithOmitableFields<T> = (T extends {
3707
+ apiKey: 'omit';
3708
+ } ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>);
3700
3709
  interface ModuleConfiguration<T> {
3701
- baseConfig: ImmutableConfiguration;
3710
+ baseConfig: ImmutableConfigurationWithOmitableFields<T>;
3702
3711
  overrides?: T;
3703
3712
  }
3704
3713
 
@@ -3479,7 +3479,7 @@ class APIError extends Error {
3479
3479
 
3480
3480
  /* eslint-disable implicit-arrow-linebreak */
3481
3481
  const defaultHeaders = {
3482
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.10-alpha.1',
3482
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.29.0',
3483
3483
  };
3484
3484
  /**
3485
3485
  * createAPIConfiguration to create a custom Configuration