@withone/sdk 0.2.0 → 0.3.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
@@ -42,8 +42,20 @@ console.log(res.status, res.data)
42
42
  compile. Const headers the action requires are injected for you, never asked.
43
43
  - **Connections.** `one.connection(key)` scopes a call to a connection; the key
44
44
  is sent as `X-One-Connection-Key`.
45
- - **From the environment.** `One.fromEnv()` reads `ONE_SECRET` and the optional
46
- `ONE_BASE_URL`.
45
+ - **From the environment.** `One.fromEnv()` reads `ONE_SECRET` or
46
+ `ONE_ACCESS_TOKEN` for the credential, plus the optional `ONE_BASE_URL`.
47
+ `ONE_SECRET` wins when both are set, since it is the broader of the two.
48
+ - **On a user's grant.** `One.withAccessToken(token)` authenticates with an
49
+ OAuth access token instead of a secret key. What it can reach is whatever
50
+ that user consented to, not the whole account.
51
+ - **Tenant scope.** A secret key carries its tenant server-side, so nothing
52
+ extra is needed. An access token does not: one token can hold grants on
53
+ several organizations, so a request that names none resolves to the user's
54
+ personal scope and an organization-owned connection reads as absent rather
55
+ than erroring. **Not selectable from Node yet** - the Rust client has
56
+ `OneBuilder::organization` / `::project`, but `ClientOptions` does not carry
57
+ them, so a token-authenticated Node client is limited to the user's own
58
+ connections for now.
47
59
 
48
60
  ### Overrides
49
61
 
package/dist/index.d.mts CHANGED
@@ -159,6 +159,28 @@ declare class ConnectionWebhooksBase {
159
159
  drainAny(): Registered[];
160
160
  }
161
161
 
162
+ /**
163
+ * Identifies the key without ever carrying its material - the secret exists
164
+ * only in the create response, never in a delivery.
165
+ */
166
+ interface ApiKeyCreatedPayload {
167
+ connection_type: string;
168
+ created_at: string;
169
+ environment: string;
170
+ event_access_id: string;
171
+ name?: string | null;
172
+ organization_id?: string | null;
173
+ project_id?: string | null;
174
+ }
175
+ interface ApiKeyRevokedPayload {
176
+ connection_type: string;
177
+ environment: string;
178
+ event_access_id: string;
179
+ name?: string | null;
180
+ organization_id?: string | null;
181
+ project_id?: string | null;
182
+ revoked_at: string;
183
+ }
162
184
  interface ConnectionCreatedPayload {
163
185
  connection_id: string;
164
186
  connection_type: string;
@@ -187,6 +209,20 @@ interface ConnectionOAuthCreatedPayload {
187
209
  platform: string;
188
210
  user_id: string;
189
211
  }
212
+ /**
213
+ * Carries the connection's state after the change, so a subscriber can apply
214
+ * it without refetching.
215
+ */
216
+ interface ConnectionUpdatedPayload {
217
+ connection_id: string;
218
+ key: string;
219
+ name?: string | null;
220
+ organization_id?: string | null;
221
+ platform: string;
222
+ project_id?: string | null;
223
+ tags: string[];
224
+ updated_at: string;
225
+ }
190
226
  interface MemberAddedPayload {
191
227
  added_at: string;
192
228
  email: string;
@@ -274,12 +310,15 @@ interface ProjectUpdatedPayload {
274
310
  updated_at: string;
275
311
  }
276
312
  /** Every event a One webhook subscription can deliver. */
277
- type WebhookEventType = 'connection.created' | 'connection.deleted' | 'connection.oauth.created' | 'member.added' | 'member.removed' | 'member.role_updated' | 'oauth.failed' | 'oauth.refreshed' | 'organization.created' | 'organization.deleted' | 'organization.updated' | 'passthrough.executed' | 'project.created' | 'project.deleted' | 'project.updated';
313
+ type WebhookEventType = 'api_key.created' | 'api_key.revoked' | 'connection.created' | 'connection.deleted' | 'connection.oauth.created' | 'connection.updated' | 'member.added' | 'member.removed' | 'member.role_updated' | 'oauth.failed' | 'oauth.refreshed' | 'organization.created' | 'organization.deleted' | 'organization.updated' | 'passthrough.executed' | 'project.created' | 'project.deleted' | 'project.updated';
278
314
  /** Maps each event to the payload its deliveries carry. */
279
315
  interface WebhookPayloads {
316
+ 'api_key.created': ApiKeyCreatedPayload;
317
+ 'api_key.revoked': ApiKeyRevokedPayload;
280
318
  'connection.created': ConnectionCreatedPayload;
281
319
  'connection.deleted': ConnectionDeletedPayload;
282
320
  'connection.oauth.created': ConnectionOAuthCreatedPayload;
321
+ 'connection.updated': ConnectionUpdatedPayload;
283
322
  'member.added': MemberAddedPayload;
284
323
  'member.removed': MemberRemovedPayload;
285
324
  'member.role_updated': MemberRoleUpdatedPayload;
@@ -307,12 +346,18 @@ declare class Webhooks extends WebhooksBase {
307
346
  protected connectionCatalog(): readonly string[];
308
347
  /** Narrows the block's scope to the typed registry. */
309
348
  connection(key: string, block: (scope: ConnectionWebhooks) => unknown): this;
349
+ /** Registers a handler for `api_key.created`. */
350
+ apiKeyCreated(handler: Handler<ApiKeyCreatedPayload>): this;
351
+ /** Registers a handler for `api_key.revoked`. */
352
+ apiKeyRevoked(handler: Handler<ApiKeyRevokedPayload>): this;
310
353
  /** Registers a handler for `connection.created`. */
311
354
  connectionCreated(handler: Handler<ConnectionCreatedPayload>): this;
312
355
  /** Registers a handler for `connection.deleted`. */
313
356
  connectionDeleted(handler: Handler<ConnectionDeletedPayload>): this;
314
357
  /** Registers a handler for `connection.oauth.created`. */
315
358
  connectionOauthCreated(handler: Handler<ConnectionOAuthCreatedPayload>): this;
359
+ /** Registers a handler for `connection.updated`. */
360
+ connectionUpdated(handler: Handler<ConnectionUpdatedPayload>): this;
316
361
  /** Registers a handler for `member.added`. */
317
362
  memberAdded(handler: Handler<MemberAddedPayload>): this;
318
363
  /** Registers a handler for `member.removed`. */
@@ -349,6 +394,8 @@ declare class ConnectionWebhooks extends ConnectionWebhooksBase {
349
394
  connectionDeleted(handler: Handler<ConnectionDeletedPayload>): this;
350
395
  /** Registers a handler for `connection.oauth.created` on this connection. */
351
396
  connectionOauthCreated(handler: Handler<ConnectionOAuthCreatedPayload>): this;
397
+ /** Registers a handler for `connection.updated` on this connection. */
398
+ connectionUpdated(handler: Handler<ConnectionUpdatedPayload>): this;
352
399
  /** Registers a handler for `oauth.failed` on this connection. */
353
400
  oauthFailed(handler: Handler<OAuthFailedPayload>): this;
354
401
  /** Registers a handler for `oauth.refreshed` on this connection. */
@@ -395,8 +442,29 @@ declare class One {
395
442
  private readonly native;
396
443
  private readonly lifecycle;
397
444
  constructor(secret: string, options?: ClientOptions);
398
- /** Creates a client from the environment (`ONE_SECRET`, `ONE_BASE_URL`). */
445
+ /**
446
+ * Creates a client that authenticates on an end user's OAuth grant.
447
+ *
448
+ * The counterpart to the constructor, as a factory because a class can only
449
+ * have one constructor and the two credentials are alternatives: a client
450
+ * authenticates as an agency with its secret key, or on a user's grant with
451
+ * their token, never both. What the token may reach is the scopes the user
452
+ * consented to, so a call outside them fails at the API, not here.
453
+ */
454
+ static withAccessToken(accessToken: string, options?: ClientOptions): One;
455
+ /**
456
+ * Creates a client from the environment: `ONE_SECRET` or `ONE_ACCESS_TOKEN`
457
+ * for the credential, plus the optional `ONE_BASE_URL`. `ONE_SECRET` wins
458
+ * when both are set.
459
+ */
399
460
  static fromEnv(): One;
461
+ /**
462
+ * Builds a facade around a native client a factory produced, bypassing the
463
+ * constructor because that one takes a secret key. One place assigns the
464
+ * fields, so a new factory cannot forget the lifecycle and leave hooks
465
+ * silently unfired.
466
+ */
467
+ private static wrapping;
400
468
  /** Scopes subsequent calls to a connection by its key. */
401
469
  connection(key: string): ConnectionScope;
402
470
  /**
package/dist/index.d.ts CHANGED
@@ -159,6 +159,28 @@ declare class ConnectionWebhooksBase {
159
159
  drainAny(): Registered[];
160
160
  }
161
161
 
162
+ /**
163
+ * Identifies the key without ever carrying its material - the secret exists
164
+ * only in the create response, never in a delivery.
165
+ */
166
+ interface ApiKeyCreatedPayload {
167
+ connection_type: string;
168
+ created_at: string;
169
+ environment: string;
170
+ event_access_id: string;
171
+ name?: string | null;
172
+ organization_id?: string | null;
173
+ project_id?: string | null;
174
+ }
175
+ interface ApiKeyRevokedPayload {
176
+ connection_type: string;
177
+ environment: string;
178
+ event_access_id: string;
179
+ name?: string | null;
180
+ organization_id?: string | null;
181
+ project_id?: string | null;
182
+ revoked_at: string;
183
+ }
162
184
  interface ConnectionCreatedPayload {
163
185
  connection_id: string;
164
186
  connection_type: string;
@@ -187,6 +209,20 @@ interface ConnectionOAuthCreatedPayload {
187
209
  platform: string;
188
210
  user_id: string;
189
211
  }
212
+ /**
213
+ * Carries the connection's state after the change, so a subscriber can apply
214
+ * it without refetching.
215
+ */
216
+ interface ConnectionUpdatedPayload {
217
+ connection_id: string;
218
+ key: string;
219
+ name?: string | null;
220
+ organization_id?: string | null;
221
+ platform: string;
222
+ project_id?: string | null;
223
+ tags: string[];
224
+ updated_at: string;
225
+ }
190
226
  interface MemberAddedPayload {
191
227
  added_at: string;
192
228
  email: string;
@@ -274,12 +310,15 @@ interface ProjectUpdatedPayload {
274
310
  updated_at: string;
275
311
  }
276
312
  /** Every event a One webhook subscription can deliver. */
277
- type WebhookEventType = 'connection.created' | 'connection.deleted' | 'connection.oauth.created' | 'member.added' | 'member.removed' | 'member.role_updated' | 'oauth.failed' | 'oauth.refreshed' | 'organization.created' | 'organization.deleted' | 'organization.updated' | 'passthrough.executed' | 'project.created' | 'project.deleted' | 'project.updated';
313
+ type WebhookEventType = 'api_key.created' | 'api_key.revoked' | 'connection.created' | 'connection.deleted' | 'connection.oauth.created' | 'connection.updated' | 'member.added' | 'member.removed' | 'member.role_updated' | 'oauth.failed' | 'oauth.refreshed' | 'organization.created' | 'organization.deleted' | 'organization.updated' | 'passthrough.executed' | 'project.created' | 'project.deleted' | 'project.updated';
278
314
  /** Maps each event to the payload its deliveries carry. */
279
315
  interface WebhookPayloads {
316
+ 'api_key.created': ApiKeyCreatedPayload;
317
+ 'api_key.revoked': ApiKeyRevokedPayload;
280
318
  'connection.created': ConnectionCreatedPayload;
281
319
  'connection.deleted': ConnectionDeletedPayload;
282
320
  'connection.oauth.created': ConnectionOAuthCreatedPayload;
321
+ 'connection.updated': ConnectionUpdatedPayload;
283
322
  'member.added': MemberAddedPayload;
284
323
  'member.removed': MemberRemovedPayload;
285
324
  'member.role_updated': MemberRoleUpdatedPayload;
@@ -307,12 +346,18 @@ declare class Webhooks extends WebhooksBase {
307
346
  protected connectionCatalog(): readonly string[];
308
347
  /** Narrows the block's scope to the typed registry. */
309
348
  connection(key: string, block: (scope: ConnectionWebhooks) => unknown): this;
349
+ /** Registers a handler for `api_key.created`. */
350
+ apiKeyCreated(handler: Handler<ApiKeyCreatedPayload>): this;
351
+ /** Registers a handler for `api_key.revoked`. */
352
+ apiKeyRevoked(handler: Handler<ApiKeyRevokedPayload>): this;
310
353
  /** Registers a handler for `connection.created`. */
311
354
  connectionCreated(handler: Handler<ConnectionCreatedPayload>): this;
312
355
  /** Registers a handler for `connection.deleted`. */
313
356
  connectionDeleted(handler: Handler<ConnectionDeletedPayload>): this;
314
357
  /** Registers a handler for `connection.oauth.created`. */
315
358
  connectionOauthCreated(handler: Handler<ConnectionOAuthCreatedPayload>): this;
359
+ /** Registers a handler for `connection.updated`. */
360
+ connectionUpdated(handler: Handler<ConnectionUpdatedPayload>): this;
316
361
  /** Registers a handler for `member.added`. */
317
362
  memberAdded(handler: Handler<MemberAddedPayload>): this;
318
363
  /** Registers a handler for `member.removed`. */
@@ -349,6 +394,8 @@ declare class ConnectionWebhooks extends ConnectionWebhooksBase {
349
394
  connectionDeleted(handler: Handler<ConnectionDeletedPayload>): this;
350
395
  /** Registers a handler for `connection.oauth.created` on this connection. */
351
396
  connectionOauthCreated(handler: Handler<ConnectionOAuthCreatedPayload>): this;
397
+ /** Registers a handler for `connection.updated` on this connection. */
398
+ connectionUpdated(handler: Handler<ConnectionUpdatedPayload>): this;
352
399
  /** Registers a handler for `oauth.failed` on this connection. */
353
400
  oauthFailed(handler: Handler<OAuthFailedPayload>): this;
354
401
  /** Registers a handler for `oauth.refreshed` on this connection. */
@@ -395,8 +442,29 @@ declare class One {
395
442
  private readonly native;
396
443
  private readonly lifecycle;
397
444
  constructor(secret: string, options?: ClientOptions);
398
- /** Creates a client from the environment (`ONE_SECRET`, `ONE_BASE_URL`). */
445
+ /**
446
+ * Creates a client that authenticates on an end user's OAuth grant.
447
+ *
448
+ * The counterpart to the constructor, as a factory because a class can only
449
+ * have one constructor and the two credentials are alternatives: a client
450
+ * authenticates as an agency with its secret key, or on a user's grant with
451
+ * their token, never both. What the token may reach is the scopes the user
452
+ * consented to, so a call outside them fails at the API, not here.
453
+ */
454
+ static withAccessToken(accessToken: string, options?: ClientOptions): One;
455
+ /**
456
+ * Creates a client from the environment: `ONE_SECRET` or `ONE_ACCESS_TOKEN`
457
+ * for the credential, plus the optional `ONE_BASE_URL`. `ONE_SECRET` wins
458
+ * when both are set.
459
+ */
399
460
  static fromEnv(): One;
461
+ /**
462
+ * Builds a facade around a native client a factory produced, bypassing the
463
+ * constructor because that one takes a secret key. One place assigns the
464
+ * fields, so a new factory cannot forget the lifecycle and leave hooks
465
+ * silently unfired.
466
+ */
467
+ private static wrapping;
400
468
  /** Scopes subsequent calls to a connection by its key. */
401
469
  connection(key: string): ConnectionScope;
402
470
  /**
package/dist/index.js CHANGED
@@ -197,9 +197,12 @@ var ConnectionWebhooksBase = (_class2 = class {
197
197
 
198
198
  // src/webhooks.generated.ts
199
199
  var ALL_WEBHOOK_EVENTS = [
200
+ "api_key.created",
201
+ "api_key.revoked",
200
202
  "connection.created",
201
203
  "connection.deleted",
202
204
  "connection.oauth.created",
205
+ "connection.updated",
203
206
  "member.added",
204
207
  "member.removed",
205
208
  "member.role_updated",
@@ -217,6 +220,7 @@ var CONNECTION_SCOPED_EVENTS = [
217
220
  "connection.created",
218
221
  "connection.deleted",
219
222
  "connection.oauth.created",
223
+ "connection.updated",
220
224
  "oauth.failed",
221
225
  "oauth.refreshed",
222
226
  "passthrough.executed"
@@ -239,6 +243,14 @@ var Webhooks = class extends WebhooksBase {
239
243
  connection(key, block) {
240
244
  return super.connection(key, block);
241
245
  }
246
+ /** Registers a handler for `api_key.created`. */
247
+ apiKeyCreated(handler) {
248
+ return this.register("api_key.created", null, handler);
249
+ }
250
+ /** Registers a handler for `api_key.revoked`. */
251
+ apiKeyRevoked(handler) {
252
+ return this.register("api_key.revoked", null, handler);
253
+ }
242
254
  /** Registers a handler for `connection.created`. */
243
255
  connectionCreated(handler) {
244
256
  return this.register("connection.created", null, handler);
@@ -251,6 +263,10 @@ var Webhooks = class extends WebhooksBase {
251
263
  connectionOauthCreated(handler) {
252
264
  return this.register("connection.oauth.created", null, handler);
253
265
  }
266
+ /** Registers a handler for `connection.updated`. */
267
+ connectionUpdated(handler) {
268
+ return this.register("connection.updated", null, handler);
269
+ }
254
270
  /** Registers a handler for `member.added`. */
255
271
  memberAdded(handler) {
256
272
  return this.register("member.added", null, handler);
@@ -313,6 +329,10 @@ var ConnectionWebhooks = class extends ConnectionWebhooksBase {
313
329
  connectionOauthCreated(handler) {
314
330
  return this.register("connection.oauth.created", handler);
315
331
  }
332
+ /** Registers a handler for `connection.updated` on this connection. */
333
+ connectionUpdated(handler) {
334
+ return this.register("connection.updated", handler);
335
+ }
316
336
  /** Registers a handler for `oauth.failed` on this connection. */
317
337
  oauthFailed(handler) {
318
338
  return this.register("oauth.failed", handler);
@@ -357,16 +377,42 @@ var One = class _One {
357
377
  }
358
378
  this.lifecycle = new CallLifecycle({ onSuccess, onError });
359
379
  }
360
- /** Creates a client from the environment (`ONE_SECRET`, `ONE_BASE_URL`). */
380
+ /**
381
+ * Creates a client that authenticates on an end user's OAuth grant.
382
+ *
383
+ * The counterpart to the constructor, as a factory because a class can only
384
+ * have one constructor and the two credentials are alternatives: a client
385
+ * authenticates as an agency with its secret key, or on a user's grant with
386
+ * their token, never both. What the token may reach is the scopes the user
387
+ * consented to, so a call outside them fails at the API, not here.
388
+ */
389
+ static withAccessToken(accessToken, options) {
390
+ const { onSuccess, onError, ...native } = _nullishCoalesce(options, () => ( {}));
391
+ return _One.wrapping(() => _nativejs.One.withAccessToken(accessToken, native), { onSuccess, onError });
392
+ }
393
+ /**
394
+ * Creates a client from the environment: `ONE_SECRET` or `ONE_ACCESS_TOKEN`
395
+ * for the credential, plus the optional `ONE_BASE_URL`. `ONE_SECRET` wins
396
+ * when both are set.
397
+ */
361
398
  static fromEnv() {
399
+ return _One.wrapping(() => _nativejs.One.fromEnv(), {});
400
+ }
401
+ /**
402
+ * Builds a facade around a native client a factory produced, bypassing the
403
+ * constructor because that one takes a secret key. One place assigns the
404
+ * fields, so a new factory cannot forget the lifecycle and leave hooks
405
+ * silently unfired.
406
+ */
407
+ static wrapping(build, hooks) {
362
408
  const client = Object.create(_One.prototype);
363
409
  const fields = client;
364
410
  try {
365
- fields.native = _nativejs.One.fromEnv();
411
+ fields.native = build();
366
412
  } catch (error) {
367
413
  throw toOneError(error);
368
414
  }
369
- fields.lifecycle = new CallLifecycle({});
415
+ fields.lifecycle = new CallLifecycle(hooks);
370
416
  return client;
371
417
  }
372
418
  /** Scopes subsequent calls to a connection by its key. */
package/dist/index.mjs CHANGED
@@ -197,9 +197,12 @@ var ConnectionWebhooksBase = class {
197
197
 
198
198
  // src/webhooks.generated.ts
199
199
  var ALL_WEBHOOK_EVENTS = [
200
+ "api_key.created",
201
+ "api_key.revoked",
200
202
  "connection.created",
201
203
  "connection.deleted",
202
204
  "connection.oauth.created",
205
+ "connection.updated",
203
206
  "member.added",
204
207
  "member.removed",
205
208
  "member.role_updated",
@@ -217,6 +220,7 @@ var CONNECTION_SCOPED_EVENTS = [
217
220
  "connection.created",
218
221
  "connection.deleted",
219
222
  "connection.oauth.created",
223
+ "connection.updated",
220
224
  "oauth.failed",
221
225
  "oauth.refreshed",
222
226
  "passthrough.executed"
@@ -239,6 +243,14 @@ var Webhooks = class extends WebhooksBase {
239
243
  connection(key, block) {
240
244
  return super.connection(key, block);
241
245
  }
246
+ /** Registers a handler for `api_key.created`. */
247
+ apiKeyCreated(handler) {
248
+ return this.register("api_key.created", null, handler);
249
+ }
250
+ /** Registers a handler for `api_key.revoked`. */
251
+ apiKeyRevoked(handler) {
252
+ return this.register("api_key.revoked", null, handler);
253
+ }
242
254
  /** Registers a handler for `connection.created`. */
243
255
  connectionCreated(handler) {
244
256
  return this.register("connection.created", null, handler);
@@ -251,6 +263,10 @@ var Webhooks = class extends WebhooksBase {
251
263
  connectionOauthCreated(handler) {
252
264
  return this.register("connection.oauth.created", null, handler);
253
265
  }
266
+ /** Registers a handler for `connection.updated`. */
267
+ connectionUpdated(handler) {
268
+ return this.register("connection.updated", null, handler);
269
+ }
254
270
  /** Registers a handler for `member.added`. */
255
271
  memberAdded(handler) {
256
272
  return this.register("member.added", null, handler);
@@ -313,6 +329,10 @@ var ConnectionWebhooks = class extends ConnectionWebhooksBase {
313
329
  connectionOauthCreated(handler) {
314
330
  return this.register("connection.oauth.created", handler);
315
331
  }
332
+ /** Registers a handler for `connection.updated` on this connection. */
333
+ connectionUpdated(handler) {
334
+ return this.register("connection.updated", handler);
335
+ }
316
336
  /** Registers a handler for `oauth.failed` on this connection. */
317
337
  oauthFailed(handler) {
318
338
  return this.register("oauth.failed", handler);
@@ -357,16 +377,42 @@ var One = class _One {
357
377
  }
358
378
  this.lifecycle = new CallLifecycle({ onSuccess, onError });
359
379
  }
360
- /** Creates a client from the environment (`ONE_SECRET`, `ONE_BASE_URL`). */
380
+ /**
381
+ * Creates a client that authenticates on an end user's OAuth grant.
382
+ *
383
+ * The counterpart to the constructor, as a factory because a class can only
384
+ * have one constructor and the two credentials are alternatives: a client
385
+ * authenticates as an agency with its secret key, or on a user's grant with
386
+ * their token, never both. What the token may reach is the scopes the user
387
+ * consented to, so a call outside them fails at the API, not here.
388
+ */
389
+ static withAccessToken(accessToken, options) {
390
+ const { onSuccess, onError, ...native } = options ?? {};
391
+ return _One.wrapping(() => NativeOne.withAccessToken(accessToken, native), { onSuccess, onError });
392
+ }
393
+ /**
394
+ * Creates a client from the environment: `ONE_SECRET` or `ONE_ACCESS_TOKEN`
395
+ * for the credential, plus the optional `ONE_BASE_URL`. `ONE_SECRET` wins
396
+ * when both are set.
397
+ */
361
398
  static fromEnv() {
399
+ return _One.wrapping(() => NativeOne.fromEnv(), {});
400
+ }
401
+ /**
402
+ * Builds a facade around a native client a factory produced, bypassing the
403
+ * constructor because that one takes a secret key. One place assigns the
404
+ * fields, so a new factory cannot forget the lifecycle and leave hooks
405
+ * silently unfired.
406
+ */
407
+ static wrapping(build, hooks) {
362
408
  const client = Object.create(_One.prototype);
363
409
  const fields = client;
364
410
  try {
365
- fields.native = NativeOne.fromEnv();
411
+ fields.native = build();
366
412
  } catch (error) {
367
413
  throw toOneError(error);
368
414
  }
369
- fields.lifecycle = new CallLifecycle({});
415
+ fields.lifecycle = new CallLifecycle(hooks);
370
416
  return client;
371
417
  }
372
418
  /** Scopes subsequent calls to a connection by its key. */
package/native.d.ts CHANGED
@@ -6,7 +6,19 @@ export type JsonValue = string | number | boolean | null | { [key: string]: Json
6
6
  export declare class One {
7
7
  /** Creates a client from a One secret key and optional configuration. */
8
8
  constructor(secret: string, options?: ClientOptions | undefined | null)
9
- /** Creates a client from the environment (`ONE_SECRET`, `ONE_BASE_URL`). */
9
+ /**
10
+ * Creates a client from an OAuth access token and optional configuration.
11
+ *
12
+ * The counterpart to the constructor, as a factory because a class can
13
+ * only have one constructor and the two credentials are alternatives: a
14
+ * client authenticates as an agency with its secret key, or on an end
15
+ * user's grant with their token, never both.
16
+ */
17
+ static withAccessToken(accessToken: string, options?: ClientOptions | undefined | null): One
18
+ /**
19
+ * Creates a client from the environment: `ONE_SECRET` or
20
+ * `ONE_ACCESS_TOKEN` for the credential, and optional `ONE_BASE_URL`.
21
+ */
10
22
  static fromEnv(): One
11
23
  /** Runs an action against a connection and resolves with the response. */
12
24
  run(request: ActionRequest): Promise<CallResult>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withone/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "The One SDK for Node — typed client over the One API.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -206,12 +206,12 @@
206
206
  "native.d.ts"
207
207
  ],
208
208
  "optionalDependencies": {
209
- "@withone/sdk-linux-x64-gnu": "0.2.0",
210
- "@withone/sdk-linux-arm64-gnu": "0.2.0",
211
- "@withone/sdk-linux-x64-musl": "0.2.0",
212
- "@withone/sdk-darwin-x64": "0.2.0",
213
- "@withone/sdk-darwin-arm64": "0.2.0",
214
- "@withone/sdk-win32-x64-msvc": "0.2.0"
209
+ "@withone/sdk-linux-x64-gnu": "0.3.0",
210
+ "@withone/sdk-linux-arm64-gnu": "0.3.0",
211
+ "@withone/sdk-linux-x64-musl": "0.3.0",
212
+ "@withone/sdk-darwin-x64": "0.3.0",
213
+ "@withone/sdk-darwin-arm64": "0.3.0",
214
+ "@withone/sdk-win32-x64-msvc": "0.3.0"
215
215
  },
216
216
  "scripts": {
217
217
  "build:native": "napi build --platform --release --js native.js --dts native.d.ts --dts-header \"export type JsonValue = string | number | boolean | null | { [key: string]: JsonValue } | JsonValue[];\n\"",