@workos-inc/node 10.2.0 → 10.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.
@@ -349,8 +349,20 @@ var FetchHttpClientResponse = class FetchHttpClientResponse extends HttpClientRe
349
349
  getRawResponse() {
350
350
  return this._res;
351
351
  }
352
- toJSON() {
353
- return this._res.headers.get("content-type")?.includes("application/json") ? this._res.json() : null;
352
+ async toJSON() {
353
+ if (!this._res.headers.get("content-type")?.includes("application/json")) return null;
354
+ const rawBody = await this._res.text();
355
+ try {
356
+ return JSON.parse(rawBody);
357
+ } catch (error) {
358
+ if (error instanceof SyntaxError) throw new ParseError({
359
+ message: error.message,
360
+ rawBody,
361
+ rawStatus: this._res.status,
362
+ requestID: this._res.headers.get("X-Request-ID") ?? ""
363
+ });
364
+ throw error;
365
+ }
354
366
  }
355
367
  static _transformHeadersToObject(headers) {
356
368
  const headersObj = {};
@@ -3588,7 +3600,7 @@ function isJson(val) {
3588
3600
  }
3589
3601
  return !0;
3590
3602
  }
3591
- const enc = /* @__PURE__ */ new TextEncoder(), dec = /* @__PURE__ */ new TextDecoder(), jsBase64Enabled = typeof Uint8Array.fromBase64 == "function" && typeof Uint8Array.prototype.toBase64 == "function" && typeof Uint8Array.prototype.toHex == "function";
3603
+ const enc = /* @__PURE__ */ new TextEncoder(), dec = /* @__PURE__ */ new TextDecoder(), jsBase64Enabled = /* @__PURE__ */ (() => typeof Uint8Array.fromBase64 == "function" && typeof Uint8Array.prototype.toBase64 == "function" && typeof Uint8Array.prototype.toHex == "function")();
3592
3604
  function b64ToU8(str) {
3593
3605
  return jsBase64Enabled ? Uint8Array.fromBase64(str, { alphabet: "base64url" }) : base64ToUint8Array$1(str);
3594
3606
  }
@@ -3633,7 +3645,7 @@ const defaults = /* @__PURE__ */ Object.freeze({
3633
3645
  ivBits: void 0,
3634
3646
  name: "SHA-256"
3635
3647
  })
3636
- }), macPrefix = "Fe26.2";
3648
+ });
3637
3649
  function randomBits(bits) {
3638
3650
  return crypto.getRandomValues(new Uint8Array(bits / 8));
3639
3651
  }
@@ -3727,7 +3739,7 @@ function normalizePassword(password) {
3727
3739
  async function seal(object, password, options) {
3728
3740
  let now = Date.now() + (options.localtimeOffsetMsec || 0), { id = "", encryption, integrity } = normalizePassword(password);
3729
3741
  if (id && !/^\w+$/.test(id)) throw Error("Invalid password id");
3730
- let { encrypted, key } = await encrypt(encryption, options.encryption, (options.encode || losslessJsonStringify)(object)), expiration = options.ttl ? now + options.ttl : "", macBaseString = macPrefix + "*" + id + "*" + key.salt + "*" + u8ToB64(key.iv) + "*" + u8ToB64(encrypted) + "*" + expiration, mac = await hmacWithPassword(integrity, options.integrity, macBaseString);
3742
+ let { encrypted, key } = await encrypt(encryption, options.encryption, (options.encode || losslessJsonStringify)(object)), expiration = options.ttl ? now + options.ttl : "", macBaseString = "Fe26.2*" + id + "*" + key.salt + "*" + u8ToB64(key.iv) + "*" + u8ToB64(encrypted) + "*" + expiration, mac = await hmacWithPassword(integrity, options.integrity, macBaseString);
3731
3743
  return macBaseString + "*" + mac.salt + "*" + mac.digest;
3732
3744
  }
3733
3745
  async function unseal(sealed, password, options) {
@@ -3975,7 +3987,7 @@ let _josePromise;
3975
3987
  * @returns Promise that resolves to the jose module
3976
3988
  */
3977
3989
  function getJose() {
3978
- return _josePromise ??= import("./webapi-CKFbiPvQ.mjs");
3990
+ return _josePromise ??= import("./webapi-S8D5YgJz.mjs");
3979
3991
  }
3980
3992
  //#endregion
3981
3993
  //#region src/user-management/session.ts
@@ -5654,6 +5666,52 @@ const serializeRemoveRoleOptions = (options) => ({
5654
5666
  }
5655
5667
  });
5656
5668
  //#endregion
5669
+ //#region src/authorization/serializers/group-role-assignment.serializer.ts
5670
+ const deserializeGroupRoleAssignment = (response) => ({
5671
+ object: response.object,
5672
+ id: response.id,
5673
+ groupId: response.group_id,
5674
+ role: response.role,
5675
+ resource: {
5676
+ id: response.resource.id,
5677
+ externalId: response.resource.external_id,
5678
+ resourceTypeSlug: response.resource.resource_type_slug
5679
+ },
5680
+ createdAt: response.created_at,
5681
+ updatedAt: response.updated_at
5682
+ });
5683
+ //#endregion
5684
+ //#region src/authorization/serializers/create-group-role-assignment-options.serializer.ts
5685
+ const serializeCreateGroupRoleAssignmentOptions = (options) => ({
5686
+ role_slug: options.roleSlug,
5687
+ ..."resourceId" in options && { resource_id: options.resourceId },
5688
+ ..."resourceExternalId" in options && {
5689
+ resource_external_id: options.resourceExternalId,
5690
+ resource_type_slug: options.resourceTypeSlug
5691
+ }
5692
+ });
5693
+ //#endregion
5694
+ //#region src/authorization/serializers/remove-group-role-assignments-options.serializer.ts
5695
+ const serializeRemoveGroupRoleAssignmentsOptions = (options) => ({
5696
+ role_slug: options.roleSlug,
5697
+ ..."resourceId" in options && { resource_id: options.resourceId },
5698
+ ..."resourceExternalId" in options && {
5699
+ resource_external_id: options.resourceExternalId,
5700
+ resource_type_slug: options.resourceTypeSlug
5701
+ }
5702
+ });
5703
+ //#endregion
5704
+ //#region src/authorization/serializers/replace-group-role-assignments-options.serializer.ts
5705
+ const serializeEntry = (entry) => ({
5706
+ role_slug: entry.roleSlug,
5707
+ ..."resourceId" in entry && { resource_id: entry.resourceId },
5708
+ ..."resourceExternalId" in entry && {
5709
+ resource_external_id: entry.resourceExternalId,
5710
+ resource_type_slug: entry.resourceTypeSlug
5711
+ }
5712
+ });
5713
+ const serializeReplaceGroupRoleAssignmentsOptions = (options) => ({ role_assignments: options.roleAssignments.map(serializeEntry) });
5714
+ //#endregion
5657
5715
  //#region src/authorization/serializers/list-effective-permissions-options.serializer.ts
5658
5716
  const serializeListEffectivePermissionsOptions = (options) => ({ ...serializePaginationOptions(options) });
5659
5717
  //#endregion
@@ -6338,6 +6396,112 @@ var Authorization = class {
6338
6396
  await this.workos.delete(`/authorization/organization_memberships/${options.organizationMembershipId}/role_assignments/${options.roleAssignmentId}`);
6339
6397
  }
6340
6398
  /**
6399
+ * List role assignments for a group
6400
+ *
6401
+ * List all role assignments granted to a group. Each assignment represents a role granted to the group on a resource.
6402
+ * @param options - Pagination options.
6403
+ * @param options.groupId - The ID of the group.
6404
+ *
6405
+ * @example
6406
+ * "group_01HXYZ123456789ABCDEFGHIJ"
6407
+ *
6408
+ * @returns {Promise<AutoPaginatable<GroupRoleAssignment>>}
6409
+ * @throws 403 response from the API.
6410
+ * @throws {NotFoundException} 404
6411
+ */
6412
+ async listGroupRoleAssignments(options) {
6413
+ const { groupId, ...paginationOptions } = options;
6414
+ const endpoint = `/authorization/groups/${groupId}/role_assignments`;
6415
+ return new AutoPaginatable(await fetchAndDeserialize(this.workos, endpoint, deserializeGroupRoleAssignment, paginationOptions), (params) => fetchAndDeserialize(this.workos, endpoint, deserializeGroupRoleAssignment, params), paginationOptions);
6416
+ }
6417
+ /**
6418
+ * Get a group role assignment
6419
+ *
6420
+ * Get a specific role assignment for a group by its ID.
6421
+ * @param options - Object containing groupId and roleAssignmentId.
6422
+ * @param options.groupId - The ID of the group.
6423
+ *
6424
+ * @example
6425
+ * "group_01HXYZ123456789ABCDEFGHIJ"
6426
+ *
6427
+ * @param options.roleAssignmentId - The ID of the group role assignment.
6428
+ *
6429
+ * @example
6430
+ * "gra_01HXYZ123456789ABCDEFGH"
6431
+ *
6432
+ * @returns {Promise<GroupRoleAssignment>}
6433
+ * @throws 403 response from the API.
6434
+ * @throws {NotFoundException} 404
6435
+ */
6436
+ async getGroupRoleAssignment(options) {
6437
+ const { data } = await this.workos.get(`/authorization/groups/${options.groupId}/role_assignments/${options.roleAssignmentId}`);
6438
+ return deserializeGroupRoleAssignment(data);
6439
+ }
6440
+ /**
6441
+ * Assign a role to a group
6442
+ *
6443
+ * Assign a role to a group on a specific resource. Omit the resource fields to assign the role on the organization itself.
6444
+ * @param options - Object containing groupId and roleSlug.
6445
+ * @returns {Promise<GroupRoleAssignment>}
6446
+ * @throws 403 response from the API.
6447
+ * @throws {NotFoundException} 404
6448
+ * @throws {ConflictException} 409
6449
+ * @throws {UnprocessableEntityException} 422
6450
+ */
6451
+ async createGroupRoleAssignment(options) {
6452
+ const { data } = await this.workos.post(`/authorization/groups/${options.groupId}/role_assignments`, serializeCreateGroupRoleAssignmentOptions(options));
6453
+ return deserializeGroupRoleAssignment(data);
6454
+ }
6455
+ /**
6456
+ * Remove a group role assignment
6457
+ *
6458
+ * Remove a specific role assignment from a group by its ID.
6459
+ * @param options - Object containing groupId and roleAssignmentId.
6460
+ * @param options.groupId - The ID of the group.
6461
+ *
6462
+ * @example
6463
+ * "group_01HXYZ123456789ABCDEFGHIJ"
6464
+ *
6465
+ * @param options.roleAssignmentId - The ID of the group role assignment to remove.
6466
+ *
6467
+ * @example
6468
+ * "gra_01HXYZ123456789ABCDEFGH"
6469
+ *
6470
+ * @returns {Promise<void>}
6471
+ * @throws 403 response from the API.
6472
+ * @throws {NotFoundException} 404
6473
+ */
6474
+ async removeGroupRoleAssignment(options) {
6475
+ await this.workos.delete(`/authorization/groups/${options.groupId}/role_assignments/${options.roleAssignmentId}`);
6476
+ }
6477
+ /**
6478
+ * Remove group role assignments by criteria
6479
+ *
6480
+ * Remove role assignments from a group that match the provided role and resource. Omit the resource fields to target the organization itself.
6481
+ * @param options - Object containing groupId and roleSlug.
6482
+ * @returns {Promise<void>}
6483
+ * @throws 403 response from the API.
6484
+ * @throws {NotFoundException} 404
6485
+ * @throws {UnprocessableEntityException} 422
6486
+ */
6487
+ async removeGroupRoleAssignments(options) {
6488
+ await this.workos.deleteWithBody(`/authorization/groups/${options.groupId}/role_assignments`, serializeRemoveGroupRoleAssignmentsOptions(options));
6489
+ }
6490
+ /**
6491
+ * Replace role assignments for a group
6492
+ *
6493
+ * Replace all of a group's role assignments with the provided list. Assignments not present in the list are removed and new ones are created. Pass an empty `roleAssignments` array to clear all assignments. Returns the resulting set of assignments.
6494
+ * @param options - Object containing groupId and roleAssignments.
6495
+ * @returns {Promise<List<GroupRoleAssignment>>}
6496
+ * @throws 403 response from the API.
6497
+ * @throws {NotFoundException} 404
6498
+ * @throws {UnprocessableEntityException} 422
6499
+ */
6500
+ async replaceGroupRoleAssignments(options) {
6501
+ const { data } = await this.workos.put(`/authorization/groups/${options.groupId}/role_assignments`, serializeReplaceGroupRoleAssignmentsOptions(options));
6502
+ return deserializeList(data, deserializeGroupRoleAssignment);
6503
+ }
6504
+ /**
6341
6505
  * List resources for organization membership
6342
6506
  *
6343
6507
  * Returns all child resources of a parent resource where the organization membership has a specific permission. This is useful for resource discovery—answering "What projects can this user access in this workspace?"
@@ -6905,7 +7069,7 @@ var Vault = class {
6905
7069
  };
6906
7070
  //#endregion
6907
7071
  //#region package.json
6908
- var version = "10.2.0";
7072
+ var version = "10.3.0";
6909
7073
  //#endregion
6910
7074
  //#region src/workos.ts
6911
7075
  const DEFAULT_HOSTNAME = "api.workos.com";
@@ -7038,12 +7202,7 @@ var WorkOS = class {
7038
7202
  });
7039
7203
  throw error;
7040
7204
  }
7041
- try {
7042
- return { data: await res.toJSON() };
7043
- } catch (error) {
7044
- await this.handleParseError(error, res);
7045
- throw error;
7046
- }
7205
+ return { data: await res.toJSON() };
7047
7206
  }
7048
7207
  async get(path, options = {}) {
7049
7208
  if (!options.skipApiKeyCheck) this.requireApiKey(path);
@@ -7063,12 +7222,7 @@ var WorkOS = class {
7063
7222
  });
7064
7223
  throw error;
7065
7224
  }
7066
- try {
7067
- return { data: await res.toJSON() };
7068
- } catch (error) {
7069
- await this.handleParseError(error, res);
7070
- throw error;
7071
- }
7225
+ return { data: await res.toJSON() };
7072
7226
  }
7073
7227
  async put(path, entity, options = {}) {
7074
7228
  if (!options.skipApiKeyCheck) this.requireApiKey(path);
@@ -7087,12 +7241,7 @@ var WorkOS = class {
7087
7241
  });
7088
7242
  throw error;
7089
7243
  }
7090
- try {
7091
- return { data: await res.toJSON() };
7092
- } catch (error) {
7093
- await this.handleParseError(error, res);
7094
- throw error;
7095
- }
7244
+ return { data: await res.toJSON() };
7096
7245
  }
7097
7246
  async patch(path, entity, options = {}) {
7098
7247
  if (!options.skipApiKeyCheck) this.requireApiKey(path);
@@ -7111,12 +7260,7 @@ var WorkOS = class {
7111
7260
  });
7112
7261
  throw error;
7113
7262
  }
7114
- try {
7115
- return { data: await res.toJSON() };
7116
- } catch (error) {
7117
- await this.handleParseError(error, res);
7118
- throw error;
7119
- }
7263
+ return { data: await res.toJSON() };
7120
7264
  }
7121
7265
  async delete(path, query) {
7122
7266
  this.requireApiKey(path);
@@ -7145,20 +7289,6 @@ var WorkOS = class {
7145
7289
  emitWarning(warning) {
7146
7290
  console.warn(`WorkOS: ${warning}`);
7147
7291
  }
7148
- async handleParseError(error, res) {
7149
- if (error instanceof SyntaxError) {
7150
- const rawResponse = res.getRawResponse();
7151
- const requestID = rawResponse.headers.get("X-Request-ID") ?? "";
7152
- const rawStatus = rawResponse.status;
7153
- const rawBody = await rawResponse.text();
7154
- throw new ParseError({
7155
- message: error.message,
7156
- rawBody,
7157
- rawStatus,
7158
- requestID
7159
- });
7160
- }
7161
- }
7162
7292
  handleHttpError({ path, error }) {
7163
7293
  if (!(error instanceof HttpClientError)) throw new Error(`Unexpected error: ${error}`, { cause: error });
7164
7294
  const { response } = error;
@@ -7285,4 +7415,4 @@ function createWorkOS(options) {
7285
7415
  //#endregion
7286
7416
  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, AutoPaginatable as h, OrganizationDomainVerificationStrategy as i, SubtleCryptoProvider as j, ApiKeyRequiredException as k, CookieSession as l, Webhooks as m, ConnectionType as n, GenerateLinkIntent as o, PKCE 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 };
7287
7417
 
7288
- //# sourceMappingURL=factory-CenLS49y.mjs.map
7418
+ //# sourceMappingURL=factory-Bh2PZgM6.mjs.map