lz-api-client
Advanced tools
Comparing version 0.6.0 to 0.6.2
@@ -1,5 +0,4 @@ | ||
import { Client } from "../../Client"; | ||
/** | ||
* Returns a client with an authenticated account. | ||
* Signs in the test account and returns the authentication payload. | ||
*/ | ||
export declare const getAuthenticatedClient: () => Promise<Client>; | ||
export declare const signIn: () => Promise<import("lz-schema").Authorization>; |
@@ -12,8 +12,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getAuthenticatedClient = void 0; | ||
exports.signIn = void 0; | ||
const vitest_1 = require("vitest"); | ||
const Client_1 = require("../../Client"); | ||
/** | ||
* Returns a client with an authenticated account. | ||
* Signs in the test account and returns the authentication payload. | ||
*/ | ||
const getAuthenticatedClient = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const signIn = () => __awaiter(void 0, void 0, void 0, function* () { | ||
Client_1.Client.prototype.storeBearerToken = vitest_1.vi.fn().mockReturnValue(null); | ||
const client = new Client_1.Client({ | ||
@@ -23,10 +25,9 @@ apiURL: process.env.TEST_API_URL, | ||
}); | ||
console.log("Signing in...", process.env.TEST_ACCOUNT_EMAIL, process.env.TEST_ACCOUNT_PASSWORD); | ||
yield client.account.signIn({ | ||
const payload = yield client.account.signIn({ | ||
email: process.env.TEST_ACCOUNT_EMAIL, | ||
password: process.env.TEST_ACCOUNT_PASSWORD, | ||
}); | ||
return client; | ||
return payload; | ||
}); | ||
exports.getAuthenticatedClient = getAuthenticatedClient; | ||
exports.signIn = signIn; | ||
//# sourceMappingURL=auth.js.map |
@@ -13,3 +13,3 @@ "use strict"; | ||
const getClientWithMockedBearerToken = (token) => { | ||
Client_1.Client.prototype.getBearerToken = vitest_1.vi.fn().mockResolvedValue("token"); | ||
Client_1.Client.prototype.getBearerToken = vitest_1.vi.fn().mockReturnValue(token); | ||
return new Client_1.Client({ | ||
@@ -16,0 +16,0 @@ apiURL: process.env.TEST_API_URL, |
@@ -15,11 +15,14 @@ "use strict"; | ||
const auth_1 = require("./helpers/auth"); | ||
const lz_schema_1 = require("lz-schema"); | ||
(0, vitest_1.describe)("WorkspaceService.search", {}, () => { | ||
const validOrganizationId = "1".repeat(24); | ||
vitest_1.test.concurrent("should return failure if not authenticated", () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const client = (0, mocks_1.getClientWithMockedBearerToken)("bad-token"); | ||
yield client.workspace.search({ organizationId: "1" }); | ||
yield client.workspace.search({ organizationId: validOrganizationId }); | ||
throw new Error("This test should have failed"); | ||
} | ||
catch (error) { | ||
(0, vitest_1.expect)(error).toHaveProperty("status", lz_schema_1.ResponseStatus.Fail); | ||
(0, vitest_1.expect)(error).toHaveProperty("message", "Unauthorized"); | ||
(0, vitest_1.expect)(error).toHaveProperty("status", "fail"); | ||
} | ||
@@ -29,16 +32,27 @@ })); | ||
try { | ||
const client = yield (0, auth_1.getAuthenticatedClient)(); | ||
const { bearerToken } = yield (0, auth_1.signIn)(); | ||
const client = (0, mocks_1.getClientWithMockedBearerToken)(bearerToken); | ||
yield client.workspace.search({ organizationId: "invalid-id" }); | ||
throw new Error("This test should have failed"); | ||
} | ||
catch (error) { | ||
(0, vitest_1.expect)(error).toHaveProperty("message", "Invalid organizationId"); | ||
(0, vitest_1.expect)(error).toHaveProperty("status", "fail"); | ||
(0, vitest_1.expect)(error).toHaveProperty("status", lz_schema_1.ResponseStatus.Fail); | ||
(0, vitest_1.expect)(error).toHaveProperty("message", "Validation error"); | ||
const clientError = error; | ||
(0, vitest_1.expect)(clientError.data).toHaveProperty("organizationId", "Invalid input"); | ||
} | ||
})); | ||
vitest_1.test.concurrent("should return success with valid token", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const client = yield (0, auth_1.getAuthenticatedClient)(); | ||
const response = yield client.workspace.search({ organizationId: "1" }); | ||
(0, vitest_1.expect)(response).toHaveProperty("status", "success"); | ||
vitest_1.test.concurrent("should return failure when the account does not have access to organization", () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const { bearerToken } = yield (0, auth_1.signIn)(); | ||
const client = (0, mocks_1.getClientWithMockedBearerToken)(bearerToken); | ||
yield client.workspace.search({ organizationId: validOrganizationId }); | ||
throw new Error("This test should have failed"); | ||
} | ||
catch (error) { | ||
(0, vitest_1.expect)(error).toHaveProperty("status", lz_schema_1.ResponseStatus.Fail); | ||
(0, vitest_1.expect)(error).toHaveProperty("message", "You don't have access to this organization"); | ||
} | ||
})); | ||
}); | ||
//# sourceMappingURL=workspace-service.test.js.map |
@@ -7,2 +7,3 @@ import { AccountService } from './services/AccountService'; | ||
import { WorkspaceService } from './services/WorkspaceService'; | ||
import { OrganizationService } from './services/OrganizationService'; | ||
type GetParams = Record<string, string | number | boolean>; | ||
@@ -19,7 +20,8 @@ type BodyParams = Record<string, any>; | ||
referrerPolicy: ReferrerPolicy | undefined; | ||
account: AccountService; | ||
campaign: CampaignService; | ||
user: UserService; | ||
journey: JourneyService; | ||
layer: LayerService; | ||
account: AccountService; | ||
organization: OrganizationService; | ||
user: UserService; | ||
workspace: WorkspaceService; | ||
@@ -26,0 +28,0 @@ constructor({ apiURL, referrerPolicy }: ClientParams); |
@@ -22,2 +22,3 @@ "use strict"; | ||
const WorkspaceService_1 = require("./services/WorkspaceService"); | ||
const OrganizationService_1 = require("./services/OrganizationService"); | ||
class Client { | ||
@@ -29,7 +30,8 @@ constructor({ apiURL, referrerPolicy }) { | ||
this.token = this.getBearerToken(); | ||
this.account = new AccountService_1.AccountService(this); | ||
this.campaign = new CampaignService_1.CampaignService(this); | ||
this.user = new UserService_1.UserService(this); | ||
this.journey = new JourneyService_1.JourneyService(this); | ||
this.layer = new LayerService_1.LayerService(this); | ||
this.account = new AccountService_1.AccountService(this); | ||
this.organization = new OrganizationService_1.OrganizationService(this); | ||
this.user = new UserService_1.UserService(this); | ||
this.workspace = new WorkspaceService_1.WorkspaceService(this); | ||
@@ -36,0 +38,0 @@ } |
@@ -15,4 +15,4 @@ import { SearchFields } from "lz-schema"; | ||
}): Promise<{ | ||
id: string; | ||
name: string; | ||
id: string; | ||
organizationId: string; | ||
@@ -19,0 +19,0 @@ domain?: string | undefined; |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,10 +19,2 @@ exports.WorkspaceService = void 0; | ||
} | ||
// /** | ||
// * Get workspace details by id | ||
// * @throws { ClientError } | ||
// * @throws { ServerError } | ||
// */ | ||
// get({ id }: { id: string }) { | ||
// return this.client.get<Workspace>(`/workspaces/${id}`, {}); | ||
// } | ||
/** | ||
@@ -24,3 +27,4 @@ * Search workspaces by name. | ||
search(params) { | ||
return this.client.get(`/organizations/:organizationId/workspaces`, params); | ||
const { organizationId } = params, rest = __rest(params, ["organizationId"]); | ||
return this.client.get(`/organizations/${organizationId}/workspaces`, rest); | ||
} | ||
@@ -27,0 +31,0 @@ } |
{ | ||
"name": "lz-api-client", | ||
"version": "0.6.0", | ||
"version": "0.6.2", | ||
"description": "client sdk for layerZ api", | ||
@@ -10,3 +10,4 @@ "main": "dist/index.js", | ||
"dev": "tsc -w", | ||
"test": "dotenv -e .env.test -- vitest" | ||
"test": "dotenv -e .env.test -- vitest", | ||
"prepublishOnly": "npm run build && npm test -- --run" | ||
}, | ||
@@ -31,4 +32,4 @@ "files": [ | ||
"dependencies": { | ||
"lz-schema": "^0.9.1" | ||
"lz-schema": "^0.9.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
55994
54
1016
5
Updatedlz-schema@^0.9.2