@workos-inc/node 7.76.0 → 7.77.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/pipes/fixtures/get-access-token-needs-reauth.json +4 -0
- package/lib/pipes/fixtures/get-access-token-no-expiry.json +10 -0
- package/lib/pipes/fixtures/get-access-token-not-installed.json +4 -0
- package/lib/pipes/fixtures/get-access-token-success.json +10 -0
- package/lib/pipes/interfaces/access-token.interface.d.ts +14 -0
- package/lib/pipes/interfaces/access-token.interface.js +2 -0
- package/lib/pipes/interfaces/get-access-token.interface.d.ts +27 -0
- package/lib/pipes/interfaces/get-access-token.interface.js +2 -0
- package/lib/pipes/pipes.d.ts +9 -0
- package/lib/pipes/pipes.js +37 -0
- package/lib/pipes/pipes.spec.d.ts +1 -0
- package/lib/pipes/pipes.spec.js +109 -0
- package/lib/pipes/serializers/access-token.serializer.d.ts +2 -0
- package/lib/pipes/serializers/access-token.serializer.js +15 -0
- package/lib/pipes/serializers/get-access-token.serializer.d.ts +3 -0
- package/lib/pipes/serializers/get-access-token.serializer.js +24 -0
- package/lib/workos.d.ts +2 -0
- package/lib/workos.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface AccessToken {
|
|
2
|
+
object: 'access_token';
|
|
3
|
+
accessToken: string;
|
|
4
|
+
expiresAt: Date | null;
|
|
5
|
+
scopes: string[];
|
|
6
|
+
missingScopes: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface SerializedAccessToken {
|
|
9
|
+
object: 'access_token';
|
|
10
|
+
access_token: string;
|
|
11
|
+
expires_at: string | null;
|
|
12
|
+
scopes: string[];
|
|
13
|
+
missing_scopes: string[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AccessToken, SerializedAccessToken } from './access-token.interface';
|
|
2
|
+
export interface GetAccessTokenOptions {
|
|
3
|
+
userId: string;
|
|
4
|
+
organizationId?: string | null;
|
|
5
|
+
}
|
|
6
|
+
export interface SerializedGetAccessTokenOptions {
|
|
7
|
+
user_id: string;
|
|
8
|
+
organization_id?: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface GetAccessTokenSuccessResponse {
|
|
11
|
+
active: true;
|
|
12
|
+
accessToken: AccessToken;
|
|
13
|
+
}
|
|
14
|
+
export interface GetAccessTokenFailureResponse {
|
|
15
|
+
active: false;
|
|
16
|
+
error: 'not_installed' | 'needs_reauthorization';
|
|
17
|
+
}
|
|
18
|
+
export type GetAccessTokenResponse = GetAccessTokenSuccessResponse | GetAccessTokenFailureResponse;
|
|
19
|
+
export interface SerializedGetAccessTokenSuccessResponse {
|
|
20
|
+
active: true;
|
|
21
|
+
access_token: SerializedAccessToken;
|
|
22
|
+
}
|
|
23
|
+
export interface SerializedGetAccessTokenFailureResponse {
|
|
24
|
+
active: false;
|
|
25
|
+
error: 'not_installed' | 'needs_reauthorization';
|
|
26
|
+
}
|
|
27
|
+
export type SerializedGetAccessTokenResponse = SerializedGetAccessTokenSuccessResponse | SerializedGetAccessTokenFailureResponse;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WorkOS } from '../workos';
|
|
2
|
+
import { GetAccessTokenOptions, GetAccessTokenResponse } from './interfaces/get-access-token.interface';
|
|
3
|
+
export declare class Pipes {
|
|
4
|
+
private readonly workos;
|
|
5
|
+
constructor(workos: WorkOS);
|
|
6
|
+
getAccessToken({ provider, ...options }: GetAccessTokenOptions & {
|
|
7
|
+
provider: string;
|
|
8
|
+
}): Promise<GetAccessTokenResponse>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.Pipes = void 0;
|
|
24
|
+
const get_access_token_serializer_1 = require("./serializers/get-access-token.serializer");
|
|
25
|
+
class Pipes {
|
|
26
|
+
constructor(workos) {
|
|
27
|
+
this.workos = workos;
|
|
28
|
+
}
|
|
29
|
+
getAccessToken(_a) {
|
|
30
|
+
var { provider } = _a, options = __rest(_a, ["provider"]);
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const { data } = yield this.workos.post(`data-integrations/${provider}/token`, (0, get_access_token_serializer_1.serializeGetAccessTokenOptions)(options));
|
|
33
|
+
return (0, get_access_token_serializer_1.deserializeGetAccessTokenResponse)(data);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Pipes = Pipes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
|
|
16
|
+
const test_utils_1 = require("../common/utils/test-utils");
|
|
17
|
+
const workos_1 = require("../workos");
|
|
18
|
+
const get_access_token_success_json_1 = __importDefault(require("./fixtures/get-access-token-success.json"));
|
|
19
|
+
const get_access_token_no_expiry_json_1 = __importDefault(require("./fixtures/get-access-token-no-expiry.json"));
|
|
20
|
+
const get_access_token_not_installed_json_1 = __importDefault(require("./fixtures/get-access-token-not-installed.json"));
|
|
21
|
+
const get_access_token_needs_reauth_json_1 = __importDefault(require("./fixtures/get-access-token-needs-reauth.json"));
|
|
22
|
+
describe('Pipes', () => {
|
|
23
|
+
let workos;
|
|
24
|
+
beforeAll(() => {
|
|
25
|
+
workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
26
|
+
apiHostname: 'api.workos.test',
|
|
27
|
+
clientId: 'proj_123',
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
31
|
+
describe('getAccessToken', () => {
|
|
32
|
+
it('returns access token with expiry date', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
(0, test_utils_1.fetchOnce)(get_access_token_success_json_1.default);
|
|
34
|
+
const response = yield workos.pipes.getAccessToken({
|
|
35
|
+
provider: 'test-provider',
|
|
36
|
+
userId: 'user_123',
|
|
37
|
+
organizationId: 'org_456',
|
|
38
|
+
});
|
|
39
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/data-integrations/test-provider/token');
|
|
40
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
41
|
+
user_id: 'user_123',
|
|
42
|
+
organization_id: 'org_456',
|
|
43
|
+
});
|
|
44
|
+
expect(response).toEqual({
|
|
45
|
+
active: true,
|
|
46
|
+
accessToken: {
|
|
47
|
+
object: 'access_token',
|
|
48
|
+
accessToken: 'test_access_token_123',
|
|
49
|
+
expiresAt: new Date('2025-10-18T12:00:00.000Z'),
|
|
50
|
+
scopes: ['read:users', 'write:users'],
|
|
51
|
+
missingScopes: [],
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}));
|
|
55
|
+
it('returns access token without expiry date', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
(0, test_utils_1.fetchOnce)(get_access_token_no_expiry_json_1.default);
|
|
57
|
+
const response = yield workos.pipes.getAccessToken({
|
|
58
|
+
provider: 'test-provider',
|
|
59
|
+
userId: 'user_789',
|
|
60
|
+
});
|
|
61
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/data-integrations/test-provider/token');
|
|
62
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
63
|
+
user_id: 'user_789',
|
|
64
|
+
organization_id: undefined,
|
|
65
|
+
});
|
|
66
|
+
expect(response).toEqual({
|
|
67
|
+
active: true,
|
|
68
|
+
accessToken: {
|
|
69
|
+
object: 'access_token',
|
|
70
|
+
accessToken: 'test_access_token_456',
|
|
71
|
+
expiresAt: null,
|
|
72
|
+
scopes: ['read:data'],
|
|
73
|
+
missingScopes: ['write:data'],
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}));
|
|
77
|
+
it('returns not_installed failure when integration is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
(0, test_utils_1.fetchOnce)(get_access_token_not_installed_json_1.default);
|
|
79
|
+
const response = yield workos.pipes.getAccessToken({
|
|
80
|
+
provider: 'test-provider',
|
|
81
|
+
userId: 'user_123',
|
|
82
|
+
});
|
|
83
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/data-integrations/test-provider/token');
|
|
84
|
+
expect(response).toEqual({
|
|
85
|
+
active: false,
|
|
86
|
+
error: 'not_installed',
|
|
87
|
+
});
|
|
88
|
+
}));
|
|
89
|
+
it('returns needs_reauthorization failure when token needs refresh', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
(0, test_utils_1.fetchOnce)(get_access_token_needs_reauth_json_1.default);
|
|
91
|
+
const response = yield workos.pipes.getAccessToken({
|
|
92
|
+
provider: 'test-provider',
|
|
93
|
+
userId: 'user_123',
|
|
94
|
+
});
|
|
95
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/data-integrations/test-provider/token');
|
|
96
|
+
expect(response).toEqual({
|
|
97
|
+
active: false,
|
|
98
|
+
error: 'needs_reauthorization',
|
|
99
|
+
});
|
|
100
|
+
}));
|
|
101
|
+
it('throws error for server errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
(0, test_utils_1.fetchOnce)({ message: 'Internal Server Error' }, { status: 500 });
|
|
103
|
+
yield expect(workos.pipes.getAccessToken({
|
|
104
|
+
provider: 'test-provider',
|
|
105
|
+
userId: 'user_123',
|
|
106
|
+
})).rejects.toThrow();
|
|
107
|
+
}));
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeAccessToken = void 0;
|
|
4
|
+
function deserializeAccessToken(serialized) {
|
|
5
|
+
return {
|
|
6
|
+
object: 'access_token',
|
|
7
|
+
accessToken: serialized.access_token,
|
|
8
|
+
expiresAt: serialized.expires_at
|
|
9
|
+
? new Date(Date.parse(serialized.expires_at))
|
|
10
|
+
: null,
|
|
11
|
+
scopes: serialized.scopes,
|
|
12
|
+
missingScopes: serialized.missing_scopes,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.deserializeAccessToken = deserializeAccessToken;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GetAccessTokenOptions, GetAccessTokenResponse, SerializedGetAccessTokenOptions, SerializedGetAccessTokenResponse } from '../interfaces/get-access-token.interface';
|
|
2
|
+
export declare function serializeGetAccessTokenOptions(options: GetAccessTokenOptions): SerializedGetAccessTokenOptions;
|
|
3
|
+
export declare function deserializeGetAccessTokenResponse(response: SerializedGetAccessTokenResponse): GetAccessTokenResponse;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeGetAccessTokenResponse = exports.serializeGetAccessTokenOptions = void 0;
|
|
4
|
+
const access_token_serializer_1 = require("./access-token.serializer");
|
|
5
|
+
function serializeGetAccessTokenOptions(options) {
|
|
6
|
+
return {
|
|
7
|
+
user_id: options.userId,
|
|
8
|
+
organization_id: options.organizationId,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
exports.serializeGetAccessTokenOptions = serializeGetAccessTokenOptions;
|
|
12
|
+
function deserializeGetAccessTokenResponse(response) {
|
|
13
|
+
if (response.active) {
|
|
14
|
+
return {
|
|
15
|
+
active: true,
|
|
16
|
+
accessToken: (0, access_token_serializer_1.deserializeAccessToken)(response.access_token),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
active: false,
|
|
21
|
+
error: response.error,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.deserializeGetAccessTokenResponse = deserializeGetAccessTokenResponse;
|
package/lib/workos.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Events } from './events/events';
|
|
|
5
5
|
import { Organizations } from './organizations/organizations';
|
|
6
6
|
import { OrganizationDomains } from './organization-domains/organization-domains';
|
|
7
7
|
import { Passwordless } from './passwordless/passwordless';
|
|
8
|
+
import { Pipes } from './pipes/pipes';
|
|
8
9
|
import { Portal } from './portal/portal';
|
|
9
10
|
import { SSO } from './sso/sso';
|
|
10
11
|
import { Webhooks } from './webhooks/webhooks';
|
|
@@ -31,6 +32,7 @@ export declare class WorkOS {
|
|
|
31
32
|
readonly organizations: Organizations;
|
|
32
33
|
readonly organizationDomains: OrganizationDomains;
|
|
33
34
|
readonly passwordless: Passwordless;
|
|
35
|
+
readonly pipes: Pipes;
|
|
34
36
|
readonly portal: Portal;
|
|
35
37
|
readonly sso: SSO;
|
|
36
38
|
readonly webhooks: Webhooks;
|
package/lib/workos.js
CHANGED
|
@@ -17,6 +17,7 @@ const events_1 = require("./events/events");
|
|
|
17
17
|
const organizations_1 = require("./organizations/organizations");
|
|
18
18
|
const organization_domains_1 = require("./organization-domains/organization-domains");
|
|
19
19
|
const passwordless_1 = require("./passwordless/passwordless");
|
|
20
|
+
const pipes_1 = require("./pipes/pipes");
|
|
20
21
|
const portal_1 = require("./portal/portal");
|
|
21
22
|
const sso_1 = require("./sso/sso");
|
|
22
23
|
const webhooks_1 = require("./webhooks/webhooks");
|
|
@@ -33,7 +34,7 @@ const actions_1 = require("./actions/actions");
|
|
|
33
34
|
const vault_1 = require("./vault/vault");
|
|
34
35
|
const conflict_exception_1 = require("./common/exceptions/conflict.exception");
|
|
35
36
|
const parse_error_1 = require("./common/exceptions/parse-error");
|
|
36
|
-
const VERSION = '7.
|
|
37
|
+
const VERSION = '7.77.0';
|
|
37
38
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
38
39
|
const HEADER_AUTHORIZATION = 'Authorization';
|
|
39
40
|
const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
|
|
@@ -48,6 +49,7 @@ class WorkOS {
|
|
|
48
49
|
this.organizations = new organizations_1.Organizations(this);
|
|
49
50
|
this.organizationDomains = new organization_domains_1.OrganizationDomains(this);
|
|
50
51
|
this.passwordless = new passwordless_1.Passwordless(this);
|
|
52
|
+
this.pipes = new pipes_1.Pipes(this);
|
|
51
53
|
this.portal = new portal_1.Portal(this);
|
|
52
54
|
this.sso = new sso_1.SSO(this);
|
|
53
55
|
this.mfa = new mfa_1.Mfa(this);
|
package/package.json
CHANGED