@workos-inc/node 7.79.3 → 7.81.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/lib/api-keys/api-keys.d.ts +1 -0
- package/lib/api-keys/api-keys.js +5 -0
- package/lib/api-keys/api-keys.spec.js +7 -0
- package/lib/api-keys/interfaces/create-organization-api-key-options.interface.d.ts +12 -0
- package/lib/api-keys/interfaces/create-organization-api-key-options.interface.js +2 -0
- package/lib/api-keys/interfaces/created-api-key.interface.d.ts +30 -0
- package/lib/api-keys/interfaces/created-api-key.interface.js +2 -0
- package/lib/api-keys/interfaces/index.d.ts +5 -0
- package/lib/api-keys/interfaces/index.js +21 -0
- package/lib/api-keys/interfaces/list-organization-api-keys-options.interface.d.ts +4 -0
- package/lib/api-keys/interfaces/list-organization-api-keys-options.interface.js +2 -0
- package/lib/api-keys/serializers/create-organization-api-key-options.serializer.d.ts +2 -0
- package/lib/api-keys/serializers/create-organization-api-key-options.serializer.js +10 -0
- package/lib/api-keys/serializers/created-api-key.serializer.d.ts +2 -0
- package/lib/api-keys/serializers/created-api-key.serializer.js +18 -0
- package/lib/api-keys/serializers/index.d.ts +4 -0
- package/lib/api-keys/serializers/index.js +20 -0
- package/lib/common/interfaces/event.interface.d.ts +27 -2
- package/lib/common/serializers/event.serializer.js +5 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/organizations/fixtures/create-organization-api-key.json +15 -0
- package/lib/organizations/fixtures/list-organization-api-keys.json +37 -0
- package/lib/organizations/organizations.d.ts +3 -0
- package/lib/organizations/organizations.js +14 -0
- package/lib/organizations/organizations.spec.js +120 -0
- package/lib/workos.js +1 -1
- package/package.json +1 -1
package/lib/api-keys/api-keys.js
CHANGED
|
@@ -21,5 +21,10 @@ class ApiKeys {
|
|
|
21
21
|
return (0, validate_api_key_serializer_1.deserializeValidateApiKeyResponse)(data);
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
+
deleteApiKey(id) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
yield this.workos.delete(`/api_keys/${id}`);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
exports.ApiKeys = ApiKeys;
|
|
@@ -58,4 +58,11 @@ describe('ApiKeys', () => {
|
|
|
58
58
|
expect(response).toEqual({ apiKey: null });
|
|
59
59
|
}));
|
|
60
60
|
});
|
|
61
|
+
describe('deleteApiKey', () => {
|
|
62
|
+
it('sends a delete request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
(0, test_utils_1.fetchOnce)({}, { status: 204 });
|
|
64
|
+
yield workos.apiKeys.deleteApiKey('api_key_01H5JQDV7R7ATEYZDEG0W5PRYS');
|
|
65
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/api_keys/api_key_01H5JQDV7R7ATEYZDEG0W5PRYS');
|
|
66
|
+
}));
|
|
67
|
+
});
|
|
61
68
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PostOptions } from '../../common/interfaces';
|
|
2
|
+
export interface CreateOrganizationApiKeyOptions {
|
|
3
|
+
organizationId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
permissions?: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface SerializedCreateOrganizationApiKeyOptions {
|
|
8
|
+
name: string;
|
|
9
|
+
permissions?: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface CreateOrganizationApiKeyRequestOptions extends Pick<PostOptions, 'idempotencyKey'> {
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface CreatedApiKey {
|
|
2
|
+
object: 'api_key';
|
|
3
|
+
id: string;
|
|
4
|
+
owner: {
|
|
5
|
+
type: 'organization';
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
name: string;
|
|
9
|
+
obfuscatedValue: string;
|
|
10
|
+
value: string;
|
|
11
|
+
lastUsedAt: string | null;
|
|
12
|
+
permissions: string[];
|
|
13
|
+
createdAt: string;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
}
|
|
16
|
+
export interface SerializedCreatedApiKey {
|
|
17
|
+
object: 'api_key';
|
|
18
|
+
id: string;
|
|
19
|
+
owner: {
|
|
20
|
+
type: 'organization';
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
name: string;
|
|
24
|
+
obfuscated_value: string;
|
|
25
|
+
value: string;
|
|
26
|
+
last_used_at: string | null;
|
|
27
|
+
permissions: string[];
|
|
28
|
+
created_at: string;
|
|
29
|
+
updated_at: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api-key.interface"), exports);
|
|
18
|
+
__exportStar(require("./create-organization-api-key-options.interface"), exports);
|
|
19
|
+
__exportStar(require("./created-api-key.interface"), exports);
|
|
20
|
+
__exportStar(require("./list-organization-api-keys-options.interface"), exports);
|
|
21
|
+
__exportStar(require("./validate-api-key.interface"), exports);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { CreateOrganizationApiKeyOptions, SerializedCreateOrganizationApiKeyOptions } from '../interfaces/create-organization-api-key-options.interface';
|
|
2
|
+
export declare function serializeCreateOrganizationApiKeyOptions(options: CreateOrganizationApiKeyOptions): SerializedCreateOrganizationApiKeyOptions;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeCreateOrganizationApiKeyOptions = void 0;
|
|
4
|
+
function serializeCreateOrganizationApiKeyOptions(options) {
|
|
5
|
+
return {
|
|
6
|
+
name: options.name,
|
|
7
|
+
permissions: options.permissions,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
exports.serializeCreateOrganizationApiKeyOptions = serializeCreateOrganizationApiKeyOptions;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeCreatedApiKey = void 0;
|
|
4
|
+
function deserializeCreatedApiKey(apiKey) {
|
|
5
|
+
return {
|
|
6
|
+
object: apiKey.object,
|
|
7
|
+
id: apiKey.id,
|
|
8
|
+
owner: apiKey.owner,
|
|
9
|
+
name: apiKey.name,
|
|
10
|
+
obfuscatedValue: apiKey.obfuscated_value,
|
|
11
|
+
value: apiKey.value,
|
|
12
|
+
lastUsedAt: apiKey.last_used_at,
|
|
13
|
+
permissions: apiKey.permissions,
|
|
14
|
+
createdAt: apiKey.created_at,
|
|
15
|
+
updatedAt: apiKey.updated_at,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.deserializeCreatedApiKey = deserializeCreatedApiKey;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api-key.serializer"), exports);
|
|
18
|
+
__exportStar(require("./create-organization-api-key-options.serializer"), exports);
|
|
19
|
+
__exportStar(require("./created-api-key.serializer"), exports);
|
|
20
|
+
__exportStar(require("./validate-api-key.serializer"), exports);
|
|
@@ -6,6 +6,7 @@ import { OrganizationMembership, OrganizationMembershipResponse } from '../../us
|
|
|
6
6
|
import { RoleEvent, RoleEventResponse } from '../../roles/interfaces/role.interface';
|
|
7
7
|
import { OrganizationDomain, OrganizationDomainResponse } from '../../organization-domains/interfaces';
|
|
8
8
|
import { AuthenticationRadarRiskDetectedEventData, AuthenticationRadarRiskDetectedEventResponseData } from '../../user-management/interfaces/authentication-radar-risk-detected-event.interface';
|
|
9
|
+
import { ApiKey, SerializedApiKey } from '../../api-keys/interfaces';
|
|
9
10
|
export interface EventBase {
|
|
10
11
|
id: string;
|
|
11
12
|
createdAt: string;
|
|
@@ -266,6 +267,10 @@ export interface InvitationRevokedEvent extends EventBase {
|
|
|
266
267
|
event: 'invitation.revoked';
|
|
267
268
|
data: InvitationEvent;
|
|
268
269
|
}
|
|
270
|
+
export interface InvitationResentEvent extends EventBase {
|
|
271
|
+
event: 'invitation.resent';
|
|
272
|
+
data: InvitationEvent;
|
|
273
|
+
}
|
|
269
274
|
export interface InvitationAcceptedEventResponse extends EventResponseBase {
|
|
270
275
|
event: 'invitation.accepted';
|
|
271
276
|
data: InvitationEventResponse;
|
|
@@ -278,6 +283,10 @@ export interface InvitationRevokedEventResponse extends EventResponseBase {
|
|
|
278
283
|
event: 'invitation.revoked';
|
|
279
284
|
data: InvitationEventResponse;
|
|
280
285
|
}
|
|
286
|
+
export interface InvitationResentEventResponse extends EventResponseBase {
|
|
287
|
+
event: 'invitation.resent';
|
|
288
|
+
data: InvitationEventResponse;
|
|
289
|
+
}
|
|
281
290
|
export interface MagicAuthCreatedEvent extends EventBase {
|
|
282
291
|
event: 'magic_auth.created';
|
|
283
292
|
data: MagicAuthEvent;
|
|
@@ -482,7 +491,23 @@ export interface OrganizationDomainDeletedEventResponse extends EventResponseBas
|
|
|
482
491
|
event: 'organization_domain.deleted';
|
|
483
492
|
data: OrganizationDomainResponse;
|
|
484
493
|
}
|
|
485
|
-
export
|
|
486
|
-
|
|
494
|
+
export interface ApiKeyCreatedEvent extends EventBase {
|
|
495
|
+
event: 'api_key.created';
|
|
496
|
+
data: ApiKey;
|
|
497
|
+
}
|
|
498
|
+
export interface ApiKeyCreatedEventResponse extends EventResponseBase {
|
|
499
|
+
event: 'api_key.created';
|
|
500
|
+
data: SerializedApiKey;
|
|
501
|
+
}
|
|
502
|
+
export interface ApiKeyDeletedEvent extends EventBase {
|
|
503
|
+
event: 'api_key.deleted';
|
|
504
|
+
data: ApiKey;
|
|
505
|
+
}
|
|
506
|
+
export interface ApiKeyDeletedEventResponse extends EventResponseBase {
|
|
507
|
+
event: 'api_key.deleted';
|
|
508
|
+
data: SerializedApiKey;
|
|
509
|
+
}
|
|
510
|
+
export type Event = AuthenticationEmailVerificationSucceededEvent | AuthenticationMfaSucceededEvent | AuthenticationOAuthFailedEvent | AuthenticationOAuthSucceededEvent | AuthenticationSSOFailedEvent | AuthenticationSSOSucceededEvent | AuthenticationPasskeyFailedEvent | AuthenticationPasskeySucceededEvent | AuthenticationPasswordFailedEvent | AuthenticationPasswordSucceededEvent | AuthenticationMagicAuthFailedEvent | AuthenticationMagicAuthSucceededEvent | AuthenticationRadarRiskDetectedEvent | ConnectionActivatedEvent | ConnectionDeactivatedEvent | ConnectionDeletedEvent | DsyncActivatedEvent | DsyncDeactivatedEvent | DsyncDeletedEvent | DsyncGroupCreatedEvent | DsyncGroupUpdatedEvent | DsyncGroupDeletedEvent | DsyncGroupUserAddedEvent | DsyncGroupUserRemovedEvent | DsyncUserCreatedEvent | DsyncUserUpdatedEvent | DsyncUserDeletedEvent | EmailVerificationCreatedEvent | InvitationAcceptedEvent | InvitationCreatedEvent | InvitationRevokedEvent | InvitationResentEvent | MagicAuthCreatedEvent | PasswordResetCreatedEvent | PasswordResetSucceededEvent | UserCreatedEvent | UserUpdatedEvent | UserDeletedEvent | OrganizationMembershipAdded | OrganizationMembershipCreated | OrganizationMembershipDeleted | OrganizationMembershipUpdated | OrganizationMembershipRemoved | RoleCreatedEvent | RoleDeletedEvent | RoleUpdatedEvent | SessionCreatedEvent | SessionRevokedEvent | OrganizationCreatedEvent | OrganizationUpdatedEvent | OrganizationDeletedEvent | OrganizationDomainVerifiedEvent | OrganizationDomainVerificationFailedEvent | OrganizationDomainCreatedEvent | OrganizationDomainUpdatedEvent | OrganizationDomainDeletedEvent | ApiKeyCreatedEvent | ApiKeyDeletedEvent;
|
|
511
|
+
export type EventResponse = AuthenticationEmailVerificationSucceededEventResponse | AuthenticationMagicAuthFailedEventResponse | AuthenticationMagicAuthSucceededEventResponse | AuthenticationMfaSucceededEventResponse | AuthenticationOAuthFailedEventResponse | AuthenticationOAuthSucceededEventResponse | AuthenticationPasskeyFailedEventResponse | AuthenticationPasskeySucceededEventResponse | AuthenticationPasswordFailedEventResponse | AuthenticationPasswordSucceededEventResponse | AuthenticationSSOFailedEventResponse | AuthenticationSSOSucceededEventResponse | AuthenticationRadarRiskDetectedEventResponse | ConnectionActivatedEventResponse | ConnectionDeactivatedEventResponse | ConnectionDeletedEventResponse | DsyncActivatedEventResponse | DsyncDeactivatedEventResponse | DsyncDeletedEventResponse | DsyncGroupCreatedEventResponse | DsyncGroupUpdatedEventResponse | DsyncGroupDeletedEventResponse | DsyncGroupUserAddedEventResponse | DsyncGroupUserRemovedEventResponse | DsyncUserCreatedEventResponse | DsyncUserUpdatedEventResponse | DsyncUserDeletedEventResponse | EmailVerificationCreatedEventResponse | InvitationAcceptedEventResponse | InvitationCreatedEventResponse | InvitationRevokedEventResponse | InvitationResentEventResponse | MagicAuthCreatedEventResponse | PasswordResetCreatedEventResponse | PasswordResetSucceededEventResponse | UserCreatedEventResponse | UserUpdatedEventResponse | UserDeletedEventResponse | OrganizationMembershipAddedResponse | OrganizationMembershipCreatedResponse | OrganizationMembershipDeletedResponse | OrganizationMembershipUpdatedResponse | OrganizationMembershipRemovedResponse | RoleCreatedEventResponse | RoleDeletedEventResponse | RoleUpdatedEventResponse | SessionCreatedEventResponse | SessionRevokedEventResponse | OrganizationCreatedResponse | OrganizationUpdatedResponse | OrganizationDeletedResponse | OrganizationDomainVerifiedEventResponse | OrganizationDomainVerificationFailedEventResponse | OrganizationDomainCreatedEventResponse | OrganizationDomainUpdatedEventResponse | OrganizationDomainDeletedEventResponse | ApiKeyCreatedEventResponse | ApiKeyDeletedEventResponse;
|
|
487
512
|
export type EventName = Event['event'];
|
|
488
513
|
export {};
|
|
@@ -10,6 +10,7 @@ const organization_membership_serializer_1 = require("../../user-management/seri
|
|
|
10
10
|
const role_serializer_1 = require("../../user-management/serializers/role.serializer");
|
|
11
11
|
const session_serializer_1 = require("../../user-management/serializers/session.serializer");
|
|
12
12
|
const authentication_radar_risk_event_serializer_1 = require("../../user-management/serializers/authentication-radar-risk-event-serializer");
|
|
13
|
+
const api_key_serializer_1 = require("../../api-keys/serializers/api-key.serializer");
|
|
13
14
|
const deserializeEvent = (event) => {
|
|
14
15
|
const eventBase = {
|
|
15
16
|
id: event.id,
|
|
@@ -62,6 +63,7 @@ const deserializeEvent = (event) => {
|
|
|
62
63
|
case 'invitation.accepted':
|
|
63
64
|
case 'invitation.created':
|
|
64
65
|
case 'invitation.revoked':
|
|
66
|
+
case 'invitation.resent':
|
|
65
67
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_4.deserializeInvitationEvent)(event.data) });
|
|
66
68
|
case 'magic_auth.created':
|
|
67
69
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_4.deserializeMagicAuthEvent)(event.data) });
|
|
@@ -95,6 +97,9 @@ const deserializeEvent = (event) => {
|
|
|
95
97
|
case 'organization_domain.updated':
|
|
96
98
|
case 'organization_domain.deleted':
|
|
97
99
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, organization_domain_serializer_1.deserializeOrganizationDomain)(event.data) });
|
|
100
|
+
case 'api_key.created':
|
|
101
|
+
case 'api_key.deleted':
|
|
102
|
+
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, api_key_serializer_1.deserializeApiKey)(event.data) });
|
|
98
103
|
}
|
|
99
104
|
};
|
|
100
105
|
exports.deserializeEvent = deserializeEvent;
|
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { WorkOS } from './workos';
|
|
|
6
6
|
import { WorkOSOptions } from './common/interfaces';
|
|
7
7
|
import { IronSessionProvider } from './common/iron-session/iron-session-provider';
|
|
8
8
|
export * from './actions/interfaces';
|
|
9
|
+
export * from './api-keys/interfaces';
|
|
9
10
|
export * from './audit-logs/interfaces';
|
|
10
11
|
export * from './common/exceptions';
|
|
11
12
|
export * from './common/interfaces';
|
package/lib/index.js
CHANGED
|
@@ -24,6 +24,7 @@ const webhooks_1 = require("./webhooks/webhooks");
|
|
|
24
24
|
const workos_1 = require("./workos");
|
|
25
25
|
const web_iron_session_provider_1 = require("./common/iron-session/web-iron-session-provider");
|
|
26
26
|
__exportStar(require("./actions/interfaces"), exports);
|
|
27
|
+
__exportStar(require("./api-keys/interfaces"), exports);
|
|
27
28
|
__exportStar(require("./audit-logs/interfaces"), exports);
|
|
28
29
|
__exportStar(require("./common/exceptions"), exports);
|
|
29
30
|
__exportStar(require("./common/interfaces"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"object": "api_key",
|
|
3
|
+
"id": "api_key_01H5JQDV7R7ATEYZDEG0W5PRYV",
|
|
4
|
+
"owner": {
|
|
5
|
+
"type": "organization",
|
|
6
|
+
"id": "org_01EHT88Z8J8795GZNQ4ZP1J81T"
|
|
7
|
+
},
|
|
8
|
+
"name": "New API Key",
|
|
9
|
+
"obfuscated_value": "sk_…9789",
|
|
10
|
+
"value": "sk_live_abc123xyz789",
|
|
11
|
+
"last_used_at": null,
|
|
12
|
+
"permissions": ["read", "write"],
|
|
13
|
+
"created_at": "2023-07-20T02:07:19.911Z",
|
|
14
|
+
"updated_at": "2023-07-20T02:07:19.911Z"
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"object": "list",
|
|
3
|
+
"data": [
|
|
4
|
+
{
|
|
5
|
+
"object": "api_key",
|
|
6
|
+
"id": "api_key_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
7
|
+
"owner": {
|
|
8
|
+
"type": "organization",
|
|
9
|
+
"id": "org_01EHT88Z8J8795GZNQ4ZP1J81T"
|
|
10
|
+
},
|
|
11
|
+
"name": "Production Key",
|
|
12
|
+
"obfuscated_value": "sk_…PRYS",
|
|
13
|
+
"last_used_at": "2023-07-20T10:30:00.000Z",
|
|
14
|
+
"permissions": ["read", "write"],
|
|
15
|
+
"created_at": "2023-07-18T02:07:19.911Z",
|
|
16
|
+
"updated_at": "2023-07-18T02:07:19.911Z"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"object": "api_key",
|
|
20
|
+
"id": "api_key_01H5JQDV7R7ATEYZDEG0W5PRYT",
|
|
21
|
+
"owner": {
|
|
22
|
+
"type": "organization",
|
|
23
|
+
"id": "org_01EHT88Z8J8795GZNQ4ZP1J81T"
|
|
24
|
+
},
|
|
25
|
+
"name": "Development Key",
|
|
26
|
+
"obfuscated_value": "sk_…PRYT",
|
|
27
|
+
"last_used_at": null,
|
|
28
|
+
"permissions": ["read"],
|
|
29
|
+
"created_at": "2023-07-19T02:07:19.911Z",
|
|
30
|
+
"updated_at": "2023-07-19T02:07:19.911Z"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"list_metadata": {
|
|
34
|
+
"before": null,
|
|
35
|
+
"after": "api_key_01H5JQDV7R7ATEYZDEG0W5PRYT"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -5,6 +5,7 @@ import { FeatureFlag } from '../feature-flags/interfaces/feature-flag.interface'
|
|
|
5
5
|
import { RoleList } from '../roles/interfaces';
|
|
6
6
|
import { ListOrganizationRolesOptions } from './interfaces/list-organization-roles-options.interface';
|
|
7
7
|
import { ListOrganizationFeatureFlagsOptions } from './interfaces/list-organization-feature-flags-options.interface';
|
|
8
|
+
import { ApiKey, ListOrganizationApiKeysOptions, CreateOrganizationApiKeyOptions, CreateOrganizationApiKeyRequestOptions, CreatedApiKey } from '../api-keys/interfaces';
|
|
8
9
|
export declare class Organizations {
|
|
9
10
|
private readonly workos;
|
|
10
11
|
constructor(workos: WorkOS);
|
|
@@ -16,4 +17,6 @@ export declare class Organizations {
|
|
|
16
17
|
updateOrganization(options: UpdateOrganizationOptions): Promise<Organization>;
|
|
17
18
|
listOrganizationRoles(options: ListOrganizationRolesOptions): Promise<RoleList>;
|
|
18
19
|
listOrganizationFeatureFlags(options: ListOrganizationFeatureFlagsOptions): Promise<AutoPaginatable<FeatureFlag>>;
|
|
20
|
+
listOrganizationApiKeys(options: ListOrganizationApiKeysOptions): Promise<AutoPaginatable<ApiKey>>;
|
|
21
|
+
createOrganizationApiKey(options: CreateOrganizationApiKeyOptions, requestOptions?: CreateOrganizationApiKeyRequestOptions): Promise<CreatedApiKey>;
|
|
19
22
|
}
|
|
@@ -26,6 +26,7 @@ const serializers_1 = require("./serializers");
|
|
|
26
26
|
const fetch_and_deserialize_1 = require("../common/utils/fetch-and-deserialize");
|
|
27
27
|
const role_serializer_1 = require("../roles/serializers/role.serializer");
|
|
28
28
|
const serializers_2 = require("../feature-flags/serializers");
|
|
29
|
+
const serializers_3 = require("../api-keys/serializers");
|
|
29
30
|
class Organizations {
|
|
30
31
|
constructor(workos) {
|
|
31
32
|
this.workos = workos;
|
|
@@ -81,5 +82,18 @@ class Organizations {
|
|
|
81
82
|
return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, `/organizations/${organizationId}/feature-flags`, serializers_2.deserializeFeatureFlag, paginationOptions), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, `/organizations/${organizationId}/feature-flags`, serializers_2.deserializeFeatureFlag, params), paginationOptions);
|
|
82
83
|
});
|
|
83
84
|
}
|
|
85
|
+
listOrganizationApiKeys(options) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const { organizationId } = options, paginationOptions = __rest(options, ["organizationId"]);
|
|
88
|
+
return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, `/organizations/${organizationId}/api_keys`, serializers_3.deserializeApiKey, paginationOptions), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, `/organizations/${organizationId}/api_keys`, serializers_3.deserializeApiKey, params), paginationOptions);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
createOrganizationApiKey(options, requestOptions = {}) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const { organizationId } = options;
|
|
94
|
+
const { data } = yield this.workos.post(`/organizations/${organizationId}/api_keys`, (0, serializers_3.serializeCreateOrganizationApiKeyOptions)(options), requestOptions);
|
|
95
|
+
return (0, serializers_3.deserializeCreatedApiKey)(data);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
84
98
|
}
|
|
85
99
|
exports.Organizations = Organizations;
|
|
@@ -22,6 +22,8 @@ const get_organization_json_1 = __importDefault(require("./fixtures/get-organiza
|
|
|
22
22
|
const list_organizations_json_1 = __importDefault(require("./fixtures/list-organizations.json"));
|
|
23
23
|
const list_organization_roles_json_1 = __importDefault(require("./fixtures/list-organization-roles.json"));
|
|
24
24
|
const list_organization_feature_flags_json_1 = __importDefault(require("./fixtures/list-organization-feature-flags.json"));
|
|
25
|
+
const list_organization_api_keys_json_1 = __importDefault(require("./fixtures/list-organization-api-keys.json"));
|
|
26
|
+
const create_organization_api_key_json_1 = __importDefault(require("./fixtures/create-organization-api-key.json"));
|
|
25
27
|
const update_organization_json_1 = __importDefault(require("./fixtures/update-organization.json"));
|
|
26
28
|
const set_stripe_customer_id_json_1 = __importDefault(require("./fixtures/set-stripe-customer-id.json"));
|
|
27
29
|
const set_stripe_customer_id_disabled_json_1 = __importDefault(require("./fixtures/set-stripe-customer-id-disabled.json"));
|
|
@@ -451,4 +453,122 @@ describe('Organizations', () => {
|
|
|
451
453
|
}));
|
|
452
454
|
});
|
|
453
455
|
});
|
|
456
|
+
describe('listOrganizationApiKeys', () => {
|
|
457
|
+
it('returns API keys for the organization', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
458
|
+
(0, test_utils_1.fetchOnce)(list_organization_api_keys_json_1.default);
|
|
459
|
+
const { data, object, listMetadata } = yield workos.organizations.listOrganizationApiKeys({
|
|
460
|
+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
461
|
+
});
|
|
462
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/api_keys');
|
|
463
|
+
expect(object).toEqual('list');
|
|
464
|
+
expect(listMetadata).toEqual({
|
|
465
|
+
before: null,
|
|
466
|
+
after: 'api_key_01H5JQDV7R7ATEYZDEG0W5PRYT',
|
|
467
|
+
});
|
|
468
|
+
expect(data).toHaveLength(2);
|
|
469
|
+
expect(data[0]).toEqual({
|
|
470
|
+
object: 'api_key',
|
|
471
|
+
id: 'api_key_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
472
|
+
owner: {
|
|
473
|
+
type: 'organization',
|
|
474
|
+
id: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
475
|
+
},
|
|
476
|
+
name: 'Production Key',
|
|
477
|
+
obfuscatedValue: 'sk_…PRYS',
|
|
478
|
+
lastUsedAt: '2023-07-20T10:30:00.000Z',
|
|
479
|
+
permissions: ['read', 'write'],
|
|
480
|
+
createdAt: '2023-07-18T02:07:19.911Z',
|
|
481
|
+
updatedAt: '2023-07-18T02:07:19.911Z',
|
|
482
|
+
});
|
|
483
|
+
}));
|
|
484
|
+
describe('with the limit option', () => {
|
|
485
|
+
it('forms the proper request to the API', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
486
|
+
(0, test_utils_1.fetchOnce)(list_organization_api_keys_json_1.default);
|
|
487
|
+
const { data } = yield workos.organizations.listOrganizationApiKeys({
|
|
488
|
+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
489
|
+
limit: 10,
|
|
490
|
+
});
|
|
491
|
+
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
492
|
+
limit: '10',
|
|
493
|
+
order: 'desc',
|
|
494
|
+
});
|
|
495
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/api_keys');
|
|
496
|
+
expect(data).toHaveLength(2);
|
|
497
|
+
}));
|
|
498
|
+
});
|
|
499
|
+
describe('with the before option', () => {
|
|
500
|
+
it('forms the proper request to the API', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
501
|
+
(0, test_utils_1.fetchOnce)(list_organization_api_keys_json_1.default);
|
|
502
|
+
const { data } = yield workos.organizations.listOrganizationApiKeys({
|
|
503
|
+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
504
|
+
before: 'api_key_before_id',
|
|
505
|
+
});
|
|
506
|
+
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
507
|
+
before: 'api_key_before_id',
|
|
508
|
+
order: 'desc',
|
|
509
|
+
});
|
|
510
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/api_keys');
|
|
511
|
+
expect(data).toHaveLength(2);
|
|
512
|
+
}));
|
|
513
|
+
});
|
|
514
|
+
describe('with the after option', () => {
|
|
515
|
+
it('forms the proper request to the API', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
516
|
+
(0, test_utils_1.fetchOnce)(list_organization_api_keys_json_1.default);
|
|
517
|
+
const { data } = yield workos.organizations.listOrganizationApiKeys({
|
|
518
|
+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
519
|
+
after: 'api_key_after_id',
|
|
520
|
+
});
|
|
521
|
+
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
522
|
+
after: 'api_key_after_id',
|
|
523
|
+
order: 'desc',
|
|
524
|
+
});
|
|
525
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/api_keys');
|
|
526
|
+
expect(data).toHaveLength(2);
|
|
527
|
+
}));
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
describe('createOrganizationApiKey', () => {
|
|
531
|
+
it('creates an API key for the organization', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
532
|
+
(0, test_utils_1.fetchOnce)(create_organization_api_key_json_1.default, { status: 201 });
|
|
533
|
+
const apiKey = yield workos.organizations.createOrganizationApiKey({
|
|
534
|
+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
535
|
+
name: 'New API Key',
|
|
536
|
+
permissions: ['read', 'write'],
|
|
537
|
+
});
|
|
538
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/api_keys');
|
|
539
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
540
|
+
name: 'New API Key',
|
|
541
|
+
permissions: ['read', 'write'],
|
|
542
|
+
});
|
|
543
|
+
expect(apiKey).toEqual({
|
|
544
|
+
object: 'api_key',
|
|
545
|
+
id: 'api_key_01H5JQDV7R7ATEYZDEG0W5PRYV',
|
|
546
|
+
owner: {
|
|
547
|
+
type: 'organization',
|
|
548
|
+
id: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
549
|
+
},
|
|
550
|
+
name: 'New API Key',
|
|
551
|
+
obfuscatedValue: 'sk_…9789',
|
|
552
|
+
value: 'sk_live_abc123xyz789',
|
|
553
|
+
lastUsedAt: null,
|
|
554
|
+
permissions: ['read', 'write'],
|
|
555
|
+
createdAt: '2023-07-20T02:07:19.911Z',
|
|
556
|
+
updatedAt: '2023-07-20T02:07:19.911Z',
|
|
557
|
+
});
|
|
558
|
+
}));
|
|
559
|
+
describe('with an idempotency key', () => {
|
|
560
|
+
it('includes an idempotency key with request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
561
|
+
(0, test_utils_1.fetchOnce)(create_organization_api_key_json_1.default, { status: 201 });
|
|
562
|
+
yield workos.organizations.createOrganizationApiKey({
|
|
563
|
+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
|
|
564
|
+
name: 'New API Key',
|
|
565
|
+
}, {
|
|
566
|
+
idempotencyKey: 'the-idempotency-key',
|
|
567
|
+
});
|
|
568
|
+
expect((0, test_utils_1.fetchHeaders)()).toMatchObject({
|
|
569
|
+
'Idempotency-Key': 'the-idempotency-key',
|
|
570
|
+
});
|
|
571
|
+
}));
|
|
572
|
+
});
|
|
573
|
+
});
|
|
454
574
|
});
|
package/lib/workos.js
CHANGED
|
@@ -35,7 +35,7 @@ const actions_1 = require("./actions/actions");
|
|
|
35
35
|
const vault_1 = require("./vault/vault");
|
|
36
36
|
const conflict_exception_1 = require("./common/exceptions/conflict.exception");
|
|
37
37
|
const parse_error_1 = require("./common/exceptions/parse-error");
|
|
38
|
-
const VERSION = '7.
|
|
38
|
+
const VERSION = '7.81.0';
|
|
39
39
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
40
40
|
const HEADER_AUTHORIZATION = 'Authorization';
|
|
41
41
|
const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
|
package/package.json
CHANGED