@workos-inc/node 9.1.0 → 9.1.1

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.
@@ -405,15 +405,26 @@ const AUTHENTICATION_ERROR_CODES = new Set([
405
405
  "mfa_verification",
406
406
  "sso_required"
407
407
  ]);
408
+ function parseAuthenticationErrorCode(value) {
409
+ if (typeof value !== "string") return;
410
+ if (!AUTHENTICATION_ERROR_CODES.has(value)) return;
411
+ return value;
412
+ }
413
+ function getAuthenticationErrorCode(data) {
414
+ return parseAuthenticationErrorCode(data.code) ?? parseAuthenticationErrorCode(data.error);
415
+ }
408
416
  function isAuthenticationErrorData(data) {
409
- return typeof data.code === "string" && AUTHENTICATION_ERROR_CODES.has(data.code);
417
+ return getAuthenticationErrorCode(data) !== void 0;
410
418
  }
411
419
  var AuthenticationException = class extends GenericServerException {
412
420
  name = "AuthenticationException";
421
+ code;
413
422
  pendingAuthenticationToken;
414
423
  constructor(status, rawData, requestID) {
415
- super(status, rawData.message, rawData, requestID);
424
+ const code = getAuthenticationErrorCode(rawData);
425
+ super(status, rawData.message ?? rawData.error_description, rawData, requestID);
416
426
  this.rawData = rawData;
427
+ this.code = code;
417
428
  this.pendingAuthenticationToken = rawData.pending_authentication_token;
418
429
  }
419
430
  };
@@ -5052,7 +5063,7 @@ var Authorization = class {
5052
5063
  * @throws {NotFoundException} 404
5053
5064
  * @throws {UnprocessableEntityException} 422
5054
5065
  */
5055
- async updateRolePermissions(organizationId, slug, options) {
5066
+ async setOrganizationRolePermissions(organizationId, slug, options) {
5056
5067
  const { data } = await this.workos.put(`/authorization/organizations/${organizationId}/roles/${slug}/permissions`, { permissions: options.permissions });
5057
5068
  return deserializeOrganizationRole(data);
5058
5069
  }
@@ -5077,7 +5088,7 @@ var Authorization = class {
5077
5088
  * @throws {NotFoundException} 404
5078
5089
  * @throws {UnprocessableEntityException} 422
5079
5090
  */
5080
- async createRolePermission(organizationId, slug, options) {
5091
+ async addOrganizationRolePermission(organizationId, slug, options) {
5081
5092
  const { data } = await this.workos.post(`/authorization/organizations/${organizationId}/roles/${slug}/permissions`, { slug: options.permissionSlug });
5082
5093
  return deserializeOrganizationRole(data);
5083
5094
  }
@@ -5104,7 +5115,7 @@ var Authorization = class {
5104
5115
  * @throws 403 response from the API.
5105
5116
  * @throws {NotFoundException} 404
5106
5117
  */
5107
- async deleteRolePermission(organizationId, slug, options) {
5118
+ async removeOrganizationRolePermission(organizationId, slug, options) {
5108
5119
  await this.workos.delete(`/authorization/organizations/${organizationId}/roles/${slug}/permissions/${options.permissionSlug}`);
5109
5120
  }
5110
5121
  /**
@@ -5288,7 +5299,7 @@ var Authorization = class {
5288
5299
  * @throws 403 response from the API.
5289
5300
  * @throws {NotFoundException} 404
5290
5301
  */
5291
- async getOrganizationResource(options) {
5302
+ async getResourceByExternalId(options) {
5292
5303
  const { organizationId, resourceTypeSlug, externalId } = options;
5293
5304
  const { data } = await this.workos.get(`/authorization/organizations/${organizationId}/resources/${resourceTypeSlug}/${externalId}`);
5294
5305
  return deserializeAuthorizationResource(data);
@@ -5320,7 +5331,7 @@ var Authorization = class {
5320
5331
  * @throws {ConflictException} 409
5321
5332
  * @throws {UnprocessableEntityException} 422
5322
5333
  */
5323
- async updateOrganizationResource(options) {
5334
+ async updateResourceByExternalId(options) {
5324
5335
  const { organizationId, resourceTypeSlug, externalId } = options;
5325
5336
  const { data } = await this.workos.patch(`/authorization/organizations/${organizationId}/resources/${resourceTypeSlug}/${externalId}`, serializeUpdateResourceByExternalIdOptions(options));
5326
5337
  return deserializeAuthorizationResource(data);
@@ -5351,7 +5362,7 @@ var Authorization = class {
5351
5362
  * @throws {NotFoundException} 404
5352
5363
  * @throws {ConflictException} 409
5353
5364
  */
5354
- async deleteOrganizationResource(options) {
5365
+ async deleteResourceByExternalId(options) {
5355
5366
  const { organizationId, resourceTypeSlug, externalId, cascadeDelete } = options;
5356
5367
  const query = cascadeDelete !== void 0 ? { cascade_delete: cascadeDelete.toString() } : void 0;
5357
5368
  await this.workos.delete(`/authorization/organizations/${organizationId}/resources/${resourceTypeSlug}/${externalId}`, query);
@@ -5384,7 +5395,7 @@ var Authorization = class {
5384
5395
  * @throws 403 response from the API.
5385
5396
  * @throws {NotFoundException} 404
5386
5397
  */
5387
- async listOrganizationMembershipRoleAssignments(options) {
5398
+ async listRoleAssignments(options) {
5388
5399
  const { organizationMembershipId, ...queryOptions } = options;
5389
5400
  const endpoint = `/authorization/organization_memberships/${organizationMembershipId}/role_assignments`;
5390
5401
  return new AutoPaginatable(await fetchAndDeserialize(this.workos, endpoint, deserializeRoleAssignment, queryOptions), (params) => fetchAndDeserialize(this.workos, endpoint, deserializeRoleAssignment, params), queryOptions);
@@ -5434,7 +5445,7 @@ var Authorization = class {
5434
5445
  * @throws 403 response from the API.
5435
5446
  * @throws {NotFoundException} 404
5436
5447
  */
5437
- async deleteOrganizationMembershipRoleAssignment(options) {
5448
+ async removeRoleAssignment(options) {
5438
5449
  await this.workos.delete(`/authorization/organization_memberships/${options.organizationMembershipId}/role_assignments/${options.roleAssignmentId}`);
5439
5450
  }
5440
5451
  /**
@@ -5455,7 +5466,7 @@ var Authorization = class {
5455
5466
  * @throws {NotFoundException} 404
5456
5467
  * @throws {UnprocessableEntityException} 422
5457
5468
  */
5458
- async listOrganizationMembershipResources(options) {
5469
+ async listResourcesForMembership(options) {
5459
5470
  const { organizationMembershipId } = options;
5460
5471
  const endpoint = `/authorization/organization_memberships/${organizationMembershipId}/resources`;
5461
5472
  const serializedOptions = serializeListResourcesForMembershipOptions(options);
@@ -5504,7 +5515,7 @@ var Authorization = class {
5504
5515
  * @throws {NotFoundException} 404
5505
5516
  * @throws {UnprocessableEntityException} 422
5506
5517
  */
5507
- async listResourceOrganizationMemberships(options) {
5518
+ async listMembershipsForResourceByExternalId(options) {
5508
5519
  const { organizationId, resourceTypeSlug, externalId } = options;
5509
5520
  const endpoint = `/authorization/organizations/${organizationId}/resources/${resourceTypeSlug}/${externalId}/organization_memberships`;
5510
5521
  const serializedOptions = serializeListMembershipsForResourceOptions(options);
@@ -5530,7 +5541,7 @@ var Authorization = class {
5530
5541
  * @throws {NotFoundException} 404
5531
5542
  * @throws {UnprocessableEntityException} 422
5532
5543
  */
5533
- async listResourcePermissions(options) {
5544
+ async listEffectivePermissions(options) {
5534
5545
  const { organizationMembershipId, resourceId } = options;
5535
5546
  const endpoint = `/authorization/resources/${resourceId}/organization_memberships/${organizationMembershipId}/permissions`;
5536
5547
  const serializedOptions = serializeListEffectivePermissionsOptions(options);
@@ -5547,8 +5558,8 @@ var Authorization = class {
5547
5558
  * @throws {UnprocessableEntityException} 422
5548
5559
  */
5549
5560
  async listEffectivePermissionsByExternalId(options) {
5550
- const { organizationMembershipId, organizationId, resourceTypeSlug, externalId } = options;
5551
- const endpoint = `/authorization/organizations/${organizationId}/resources/${resourceTypeSlug}/${externalId}/organization_memberships/${organizationMembershipId}/permissions`;
5561
+ const { organizationMembershipId, resourceTypeSlug, externalId } = options;
5562
+ const endpoint = `/authorization/organization_memberships/${organizationMembershipId}/resources/${resourceTypeSlug}/${externalId}/permissions`;
5552
5563
  const serializedOptions = serializeListEffectivePermissionsOptions(options);
5553
5564
  return new AutoPaginatable(await fetchAndDeserialize(this.workos, endpoint, deserializePermission, serializedOptions), (params) => fetchAndDeserialize(this.workos, endpoint, deserializePermission, params), serializedOptions);
5554
5565
  }
@@ -5847,7 +5858,7 @@ function extractBunVersionFromUserAgent() {
5847
5858
  }
5848
5859
  //#endregion
5849
5860
  //#region package.json
5850
- var version = "9.1.0";
5861
+ var version = "9.1.1";
5851
5862
  //#endregion
5852
5863
  //#region src/workos.ts
5853
5864
  const DEFAULT_HOSTNAME = "api.workos.com";
@@ -6137,14 +6148,14 @@ var WorkOS = class {
6137
6148
  const retryAfter = headers.get("Retry-After");
6138
6149
  throw new RateLimitExceededException(data.message, requestID, retryAfter ? Number(retryAfter) : null);
6139
6150
  }
6140
- default: if (error || errorDescription) throw new OauthException(status, requestID, error, errorDescription, data);
6151
+ default: if (isAuthenticationErrorData(data)) throw new AuthenticationException(status, data, requestID);
6152
+ else if (error || errorDescription) throw new OauthException(status, requestID, error, errorDescription, data);
6141
6153
  else if (code && errors) throw new BadRequestException({
6142
6154
  code,
6143
6155
  errors,
6144
6156
  message,
6145
6157
  requestID
6146
6158
  });
6147
- else if (isAuthenticationErrorData(data)) throw new AuthenticationException(status, data, requestID);
6148
6159
  else throw new GenericServerException(status, data.message, data, requestID);
6149
6160
  }
6150
6161
  }
@@ -6232,4 +6243,4 @@ function createWorkOS(options) {
6232
6243
  //#endregion
6233
6244
  export { FetchHttpClient as A, NoApiKeyProvidedException as C, isAuthenticationErrorData as D, AuthenticationException as E, GenericServerException as O, NotFoundException as S, BadRequestException as T, UnprocessableEntityException as _, DomainDataState as a, RateLimitExceededException as b, FeatureFlagsRuntimeClient as c, serializeRevokeSessionOptions as d, AuthenticateWithSessionCookieFailureReason as f, Actions as g, Webhooks as h, OrganizationDomainVerificationStrategy as i, SubtleCryptoProvider as j, ApiKeyRequiredException as k, CookieSession as l, PKCE as m, ConnectionType as n, GenerateLinkIntent as o, AutoPaginatable as p, OrganizationDomainState as r, WorkOS as s, createWorkOS as t, RefreshSessionFailureReason as u, UnauthorizedException as v, ConflictException as w, OauthException as x, SignatureVerificationException as y };
6234
6245
 
6235
- //# sourceMappingURL=factory-B7cG7pDB.mjs.map
6246
+ //# sourceMappingURL=factory-BQ0MwKRy.mjs.map