@workos-inc/node 7.50.1 → 7.52.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.
@@ -1,6 +1,6 @@
1
1
  import { List, PaginationOptions } from '../interfaces';
2
2
  export declare class AutoPaginatable<T> {
3
- private list;
3
+ protected list: List<T>;
4
4
  private apiCall;
5
5
  readonly object: 'list';
6
6
  readonly options: PaginationOptions;
package/lib/fga/fga.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { WorkOS } from '../workos';
2
2
  import { Resource, CheckBatchOptions, CheckOptions, CheckRequestOptions, CheckResult, CreateResourceOptions, DeleteResourceOptions, ListResourcesOptions, ListWarrantsRequestOptions, ListWarrantsOptions, QueryOptions, QueryRequestOptions, QueryResult, ResourceInterface, ResourceOptions, UpdateResourceOptions, WriteWarrantOptions, Warrant, WarrantToken, BatchWriteResourcesOptions } from './interfaces';
3
3
  import { AutoPaginatable } from '../common/utils/pagination';
4
+ import { FgaPaginatable } from './utils/fga-paginatable';
4
5
  export declare class FGA {
5
6
  private readonly workos;
6
7
  constructor(workos: WorkOS);
@@ -15,5 +16,5 @@ export declare class FGA {
15
16
  writeWarrant(options: WriteWarrantOptions): Promise<WarrantToken>;
16
17
  batchWriteWarrants(options: WriteWarrantOptions[]): Promise<WarrantToken>;
17
18
  listWarrants(options?: ListWarrantsOptions, requestOptions?: ListWarrantsRequestOptions): Promise<AutoPaginatable<Warrant>>;
18
- query(options: QueryOptions, requestOptions?: QueryRequestOptions): Promise<AutoPaginatable<QueryResult>>;
19
+ query(options: QueryOptions, requestOptions?: QueryRequestOptions): Promise<FgaPaginatable<QueryResult>>;
19
20
  }
package/lib/fga/fga.js CHANGED
@@ -15,6 +15,8 @@ const serializers_1 = require("./serializers");
15
15
  const interface_check_1 = require("./utils/interface-check");
16
16
  const pagination_1 = require("../common/utils/pagination");
17
17
  const fetch_and_deserialize_1 = require("../common/utils/fetch-and-deserialize");
18
+ const fga_paginatable_1 = require("./utils/fga-paginatable");
19
+ const fetch_and_deserialize_list_1 = require("./utils/fetch-and-deserialize-list");
18
20
  class FGA {
19
21
  constructor(workos) {
20
22
  this.workos = workos;
@@ -104,7 +106,7 @@ class FGA {
104
106
  }
105
107
  query(options, requestOptions = {}) {
106
108
  return __awaiter(this, void 0, void 0, function* () {
107
- return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/fga/v1/query', serializers_1.deserializeQueryResult, (0, serializers_1.serializeQueryOptions)(options), requestOptions), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/fga/v1/query', serializers_1.deserializeQueryResult, params, requestOptions), (0, serializers_1.serializeQueryOptions)(options));
109
+ return new fga_paginatable_1.FgaPaginatable(yield (0, fetch_and_deserialize_list_1.fetchAndDeserializeFGAList)(this.workos, '/fga/v1/query', serializers_1.deserializeQueryResult, (0, serializers_1.serializeQueryOptions)(options), requestOptions), (params) => (0, fetch_and_deserialize_list_1.fetchAndDeserializeFGAList)(this.workos, '/fga/v1/query', serializers_1.deserializeQueryResult, params, requestOptions), (0, serializers_1.serializeQueryOptions)(options));
108
110
  });
109
111
  }
110
112
  }
@@ -48,6 +48,56 @@ describe('FGA', () => {
48
48
  warrantToken: 'abc',
49
49
  });
50
50
  }));
51
+ it('deserializes warnings in check response', () => __awaiter(void 0, void 0, void 0, function* () {
52
+ (0, test_utils_1.fetchOnce)({
53
+ result: 'authorized',
54
+ is_implicit: false,
55
+ warrant_token: 'abc',
56
+ warnings: [
57
+ {
58
+ code: 'missing_context_keys',
59
+ message: 'Missing required context keys',
60
+ keys: ['tenant_id', 'region'],
61
+ },
62
+ {
63
+ code: 'some_other_warning',
64
+ message: 'Some other warning message',
65
+ },
66
+ ],
67
+ });
68
+ const checkResult = yield workos.fga.check({
69
+ checks: [
70
+ {
71
+ resource: {
72
+ resourceType: 'role',
73
+ resourceId: 'admin',
74
+ },
75
+ relation: 'member',
76
+ subject: {
77
+ resourceType: 'user',
78
+ resourceId: 'user_123',
79
+ },
80
+ },
81
+ ],
82
+ });
83
+ expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/check');
84
+ expect(checkResult).toMatchObject({
85
+ result: 'authorized',
86
+ isImplicit: false,
87
+ warrantToken: 'abc',
88
+ warnings: [
89
+ {
90
+ code: 'missing_context_keys',
91
+ message: 'Missing required context keys',
92
+ keys: ['tenant_id', 'region'],
93
+ },
94
+ {
95
+ code: 'some_other_warning',
96
+ message: 'Some other warning message',
97
+ },
98
+ ],
99
+ });
100
+ }));
51
101
  });
52
102
  describe('createResource', () => {
53
103
  it('creates resource', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -606,6 +656,100 @@ describe('FGA', () => {
606
656
  },
607
657
  ]);
608
658
  }));
659
+ it('deserializes warnings in query response', () => __awaiter(void 0, void 0, void 0, function* () {
660
+ (0, test_utils_1.fetchOnce)({
661
+ data: [
662
+ {
663
+ resource_type: 'role',
664
+ resource_id: 'admin',
665
+ warrant: {
666
+ resource_type: 'role',
667
+ resource_id: 'admin',
668
+ relation: 'member',
669
+ subject: {
670
+ resource_type: 'user',
671
+ resource_id: 'user_123',
672
+ },
673
+ },
674
+ is_implicit: false,
675
+ },
676
+ {
677
+ resource_type: 'role',
678
+ resource_id: 'manager',
679
+ warrant: {
680
+ resource_type: 'role',
681
+ resource_id: 'manager',
682
+ relation: 'member',
683
+ subject: {
684
+ resource_type: 'user',
685
+ resource_id: 'user_123',
686
+ },
687
+ },
688
+ is_implicit: true,
689
+ },
690
+ ],
691
+ list_metadata: {
692
+ before: null,
693
+ after: null,
694
+ },
695
+ warnings: [
696
+ {
697
+ code: 'missing_context_keys',
698
+ message: 'Missing required context keys',
699
+ keys: ['tenant_id'],
700
+ },
701
+ {
702
+ code: 'some_other_warning',
703
+ message: 'Some other warning message',
704
+ },
705
+ ],
706
+ });
707
+ const result = yield workos.fga.query({
708
+ q: 'select role where user:user_123 is member',
709
+ });
710
+ expect((0, test_utils_1.fetchURL)()).toContain('/fga/v1/query');
711
+ expect(result.data).toMatchObject([
712
+ {
713
+ resourceType: 'role',
714
+ resourceId: 'admin',
715
+ warrant: {
716
+ resourceType: 'role',
717
+ resourceId: 'admin',
718
+ relation: 'member',
719
+ subject: {
720
+ resourceType: 'user',
721
+ resourceId: 'user_123',
722
+ },
723
+ },
724
+ isImplicit: false,
725
+ },
726
+ {
727
+ resourceType: 'role',
728
+ resourceId: 'manager',
729
+ warrant: {
730
+ resourceType: 'role',
731
+ resourceId: 'manager',
732
+ relation: 'member',
733
+ subject: {
734
+ resourceType: 'user',
735
+ resourceId: 'user_123',
736
+ },
737
+ },
738
+ isImplicit: true,
739
+ },
740
+ ]);
741
+ expect(result.warnings).toMatchObject([
742
+ {
743
+ code: 'missing_context_keys',
744
+ message: 'Missing required context keys',
745
+ keys: ['tenant_id'],
746
+ },
747
+ {
748
+ code: 'some_other_warning',
749
+ message: 'Some other warning message',
750
+ },
751
+ ]);
752
+ }));
609
753
  it('sends correct params and options', () => __awaiter(void 0, void 0, void 0, function* () {
610
754
  (0, test_utils_1.fetchOnce)({
611
755
  data: [
@@ -2,6 +2,7 @@ import { ResourceInterface, ResourceOptions } from './resource.interface';
2
2
  import { PolicyContext, SerializedSubject, Subject } from './warrant.interface';
3
3
  import { CheckOp } from './check-op.enum';
4
4
  import { PostOptions } from '../../common/interfaces';
5
+ import { Warning } from './warning.interface';
5
6
  export interface CheckWarrantOptions {
6
7
  resource: ResourceInterface | ResourceOptions;
7
8
  relation: string;
@@ -39,6 +40,7 @@ export interface CheckResultResponse {
39
40
  is_implicit: boolean;
40
41
  warrant_token: string;
41
42
  debug_info?: DebugInfoResponse;
43
+ warnings?: Warning[];
42
44
  }
43
45
  export interface DebugInfo {
44
46
  processingTime: number;
@@ -67,12 +69,14 @@ export interface CheckResultInterface {
67
69
  isImplicit: boolean;
68
70
  warrantToken: string;
69
71
  debugInfo?: DebugInfo;
72
+ warnings?: Warning[];
70
73
  }
71
74
  export declare class CheckResult implements CheckResultInterface {
72
75
  result: string;
73
76
  isImplicit: boolean;
74
77
  warrantToken: string;
75
78
  debugInfo?: DebugInfo;
79
+ warnings?: Warning[];
76
80
  constructor(json: CheckResultResponse);
77
81
  isAuthorized(): boolean;
78
82
  }
@@ -14,6 +14,7 @@ class CheckResult {
14
14
  decisionTree: (0, check_options_serializer_1.deserializeDecisionTreeNode)(json.debug_info.decision_tree),
15
15
  }
16
16
  : undefined;
17
+ this.warnings = json.warnings;
17
18
  }
18
19
  isAuthorized() {
19
20
  return this.result === CHECK_RESULT_AUTHORIZED;
@@ -0,0 +1,8 @@
1
+ import { List, ListResponse } from '../../common/interfaces';
2
+ import { Warning } from './warning.interface';
3
+ export interface FGAListResponse<T> extends ListResponse<T> {
4
+ warnings?: Warning[];
5
+ }
6
+ export interface FGAList<T> extends List<T> {
7
+ warnings?: Warning[];
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ export interface BaseWarning {
2
+ code: string;
3
+ message: string;
4
+ }
5
+ export interface MissingContextKeysWarning extends BaseWarning {
6
+ code: 'missing_context_keys';
7
+ keys: string[];
8
+ }
9
+ export type Warning = BaseWarning | MissingContextKeysWarning;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -10,3 +10,4 @@ export * from './resource.serializer';
10
10
  export * from './warrant-token.serializer';
11
11
  export * from './warrant.serializer';
12
12
  export * from './write-warrant-options.serializer';
13
+ export * from './list.serializer';
@@ -26,3 +26,4 @@ __exportStar(require("./resource.serializer"), exports);
26
26
  __exportStar(require("./warrant-token.serializer"), exports);
27
27
  __exportStar(require("./warrant.serializer"), exports);
28
28
  __exportStar(require("./write-warrant-options.serializer"), exports);
29
+ __exportStar(require("./list.serializer"), exports);
@@ -0,0 +1,5 @@
1
+ import { FGAList } from '../interfaces/list.interface';
2
+ import { ListResponse } from '../../common/interfaces';
3
+ export declare const deserializeFGAList: <T, U>(response: ListResponse<T> & {
4
+ warnings?: any[] | undefined;
5
+ }, deserializeFn: (data: T) => U) => FGAList<U>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeFGAList = void 0;
4
+ const deserializeFGAList = (response, deserializeFn) => ({
5
+ object: 'list',
6
+ data: response.data.map(deserializeFn),
7
+ listMetadata: response.list_metadata,
8
+ warnings: response.warnings,
9
+ });
10
+ exports.deserializeFGAList = deserializeFGAList;
@@ -1,2 +1,7 @@
1
1
  import { QueryResult, QueryResultResponse } from '../interfaces';
2
+ import { Warning } from '../interfaces/warning.interface';
3
+ import { ListResponse } from '../../common/interfaces';
4
+ export interface QueryResultListResponse extends ListResponse<QueryResultResponse> {
5
+ warnings?: Warning[];
6
+ }
2
7
  export declare const deserializeQueryResult: (queryResult: QueryResultResponse) => QueryResult;
@@ -0,0 +1,5 @@
1
+ import { WorkOS } from '../../workos';
2
+ import { FGAList } from '../interfaces/list.interface';
3
+ import { QueryRequestOptions } from '../interfaces';
4
+ import { PaginationOptions } from '../../common/interfaces';
5
+ export declare const fetchAndDeserializeFGAList: <T, U>(workos: WorkOS, endpoint: string, deserializeFn: (data: T) => U, options?: PaginationOptions, requestOptions?: QueryRequestOptions) => Promise<FGAList<U>>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.fetchAndDeserializeFGAList = void 0;
13
+ const list_serializer_1 = require("../serializers/list.serializer");
14
+ const fetchAndDeserializeFGAList = (workos, endpoint, deserializeFn, options, requestOptions) => __awaiter(void 0, void 0, void 0, function* () {
15
+ const { data: response } = yield workos.get(endpoint, Object.assign({ query: options }, requestOptions));
16
+ return (0, list_serializer_1.deserializeFGAList)(response, deserializeFn);
17
+ });
18
+ exports.fetchAndDeserializeFGAList = fetchAndDeserializeFGAList;
@@ -0,0 +1,9 @@
1
+ import { AutoPaginatable } from '../../common/utils/pagination';
2
+ import { FGAList } from '../interfaces/list.interface';
3
+ import { Warning } from '../interfaces/warning.interface';
4
+ import { PaginationOptions } from '../../common/interfaces';
5
+ export declare class FgaPaginatable<T> extends AutoPaginatable<T> {
6
+ protected list: FGAList<T>;
7
+ constructor(list: FGAList<T>, apiCall: (params: PaginationOptions) => Promise<FGAList<T>>, options?: PaginationOptions);
8
+ get warnings(): Warning[] | undefined;
9
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FgaPaginatable = void 0;
4
+ const pagination_1 = require("../../common/utils/pagination");
5
+ class FgaPaginatable extends pagination_1.AutoPaginatable {
6
+ constructor(list, apiCall, options) {
7
+ super(list, apiCall, options);
8
+ }
9
+ get warnings() {
10
+ return this.list.warnings;
11
+ }
12
+ }
13
+ exports.FgaPaginatable = FgaPaginatable;
@@ -6,6 +6,7 @@
6
6
  "id": "om_01H5JQDV7R7ATEYZDEG0W5PRYS",
7
7
  "user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
8
8
  "organization_id": "organization_01H5JQDV7R7ATEYZDEG0W5PRYS",
9
+ "organization_name": "Example Organization",
9
10
  "status": "active",
10
11
  "created_at": "2023-07-18T02:07:19.911Z",
11
12
  "updated_at": "2023-07-18T02:07:19.911Z"
@@ -4,6 +4,7 @@ export interface OrganizationMembership {
4
4
  object: 'organization_membership';
5
5
  id: string;
6
6
  organizationId: string;
7
+ organizationName: string;
7
8
  status: OrganizationMembershipStatus;
8
9
  userId: string;
9
10
  createdAt: string;
@@ -14,6 +15,7 @@ export interface OrganizationMembershipResponse {
14
15
  object: 'organization_membership';
15
16
  id: string;
16
17
  organization_id: string;
18
+ organization_name: string;
17
19
  status: OrganizationMembershipStatus;
18
20
  user_id: string;
19
21
  created_at: string;
@@ -1,6 +1,7 @@
1
1
  import { PasswordHashType } from './password-hash-type.interface';
2
2
  export interface UpdateUserOptions {
3
3
  userId: string;
4
+ email?: string;
4
5
  firstName?: string;
5
6
  lastName?: string;
6
7
  emailVerified?: boolean;
@@ -11,6 +12,7 @@ export interface UpdateUserOptions {
11
12
  metadata?: Record<string, string | null>;
12
13
  }
13
14
  export interface SerializedUpdateUserOptions {
15
+ email?: string;
14
16
  first_name?: string;
15
17
  last_name?: string;
16
18
  email_verified?: boolean;
@@ -6,6 +6,7 @@ const deserializeOrganizationMembership = (organizationMembership) => ({
6
6
  id: organizationMembership.id,
7
7
  userId: organizationMembership.user_id,
8
8
  organizationId: organizationMembership.organization_id,
9
+ organizationName: organizationMembership.organization_name,
9
10
  status: organizationMembership.status,
10
11
  createdAt: organizationMembership.created_at,
11
12
  updatedAt: organizationMembership.updated_at,
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serializeUpdateUserOptions = void 0;
4
4
  const serializeUpdateUserOptions = (options) => ({
5
+ email: options.email,
6
+ email_verified: options.emailVerified,
5
7
  first_name: options.firstName,
6
8
  last_name: options.lastName,
7
- email_verified: options.emailVerified,
8
9
  password: options.password,
9
10
  password_hash: options.passwordHash,
10
11
  password_hash_type: options.passwordHashType,
@@ -1271,6 +1271,7 @@ describe('UserManagement', () => {
1271
1271
  {
1272
1272
  object: 'organization_membership',
1273
1273
  organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
1274
+ organizationName: 'Example Organization',
1274
1275
  userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
1275
1276
  status: 'active',
1276
1277
  },
package/lib/workos.js CHANGED
@@ -31,7 +31,7 @@ const widgets_1 = require("./widgets/widgets");
31
31
  const actions_1 = require("./actions/actions");
32
32
  const vault_1 = require("./vault/vault");
33
33
  const conflict_exception_1 = require("./common/exceptions/conflict.exception");
34
- const VERSION = '7.50.1';
34
+ const VERSION = '7.52.0';
35
35
  const DEFAULT_HOSTNAME = 'api.workos.com';
36
36
  const HEADER_AUTHORIZATION = 'Authorization';
37
37
  const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.50.1",
2
+ "version": "7.52.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",