Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Aug 11, 2023
1 parent 4a67013 commit bd7a4f5
Show file tree
Hide file tree
Showing 108 changed files with 1,489 additions and 901 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flagright",
"version": "0.0.4",
"version": "0.1.0",
"private": false,
"repository": "https://github.com/flagright/flagright-node",
"main": "./index.js",
Expand All @@ -14,7 +14,7 @@
"@ungap/url-search-params": "0.2.2",
"url-join": "4.0.1",
"@types/url-join": "4.0.1",
"axios": "1.4.0"
"axios": "0.27.2"
},
"devDependencies": {
"@types/node": "17.0.33",
Expand Down
702 changes: 28 additions & 674 deletions src/Client.ts

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/api/client/requests/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./types";
export * from "./errors";
export * from "./client";
export * from "./resources";
118 changes: 118 additions & 0 deletions src/api/resources/businessUserEvents/client/Client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as environments from "../../../../environments";
import * as core from "../../../../core";
import * as Flagright from "../../..";
import { default as URLSearchParams } from "@ungap/url-search-params";
import * as serializers from "../../../../serialization";
import urlJoin from "url-join";
import * as errors from "../../../../errors";

export declare namespace BusinessUserEvents {
interface Options {
environment?: core.Supplier<environments.FlagrightEnvironment | string>;
apiKey: core.Supplier<string>;
}

interface RequestOptions {
timeoutInSeconds?: number;
}
}

export class BusinessUserEvents {
constructor(protected readonly _options: BusinessUserEvents.Options) {}

/**
* ## POST Business User Events
*
* `/events/business/user` endpoint allows you to operate on the Business User Events entity.
*
* User events are created after the initial `POST /business/users` call (which creates a user) and are used to:
*
* * Update the STATE and KYC Status of the user, using the `userStateDetails` or `kycStatusDetails` field
* * Update the user details, using the `updatedBusinessUserAttributes` field.
*
* > If you have neither of the above two use cases, you do not need to use user events.
*
* ### Payload
*
* Each user event needs three mandatory fields:
*
* * `timestamp`- the timestamp of when the event was created or occured in your system
* * `userId` - The ID of the transaction for which this event is generated.
*
* In order to make individual events retrievable, you also need to pass in a unique `eventId` to the request body.
*
* @throws {@link Flagright.BadRequestError}
* @throws {@link Flagright.UnauthorizedError}
* @throws {@link Flagright.TooManyRequestsError}
*/
public async create(
request: Flagright.BusinessUserEvent,
requestOptions?: BusinessUserEvents.RequestOptions
): Promise<Flagright.BusinessWithRulesResult> {
const { allowUserTypeConversion, ..._body } = request;
const _queryParams = new URLSearchParams();
if (allowUserTypeConversion != null) {
_queryParams.append("allowUserTypeConversion", allowUserTypeConversion);
}

const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.FlagrightEnvironment.Default,
"events/business/user"
),
method: "POST",
headers: {
"x-api-key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "flagright",
"X-Fern-SDK-Version": "0.1.0",
},
contentType: "application/json",
queryParameters: _queryParams,
body: await serializers.BusinessUserEvent.jsonOrThrow(_body, { unrecognizedObjectKeys: "strip" }),
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
});
if (_response.ok) {
return await serializers.BusinessWithRulesResult.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Flagright.BadRequestError(_response.error.body);
case 401:
throw new Flagright.UnauthorizedError(_response.error.body);
case 429:
throw new Flagright.TooManyRequestsError(_response.error.body);
default:
throw new errors.FlagrightError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}

switch (_response.error.reason) {
case "non-json":
throw new errors.FlagrightError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.FlagrightTimeoutError();
case "unknown":
throw new errors.FlagrightError({
message: _response.error.errorMessage,
});
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
* This file was auto-generated by Fern from our API Definition.
*/

import * as Flagright from "../..";
import * as Flagright from "../../../..";

export interface BusinessUserEvent {
/**
* Boolean string whether Flagright should allow a Business user event to be applied to a Consumer user with the same user ID. This will converts a Consumer user to a Business user.
*/
allowUserTypeConversion?: Flagright.BooleanString;
/** Timestamp of the event */
timestamp: number;
/** Transaction ID the event pertains to <span style="white-space: nowrap">`non-empty`</span> */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { BusinessUserEvent } from "./BusinessUserEvent";
1 change: 1 addition & 0 deletions src/api/resources/businessUserEvents/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./client";
170 changes: 170 additions & 0 deletions src/api/resources/businessUsers/client/Client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as environments from "../../../../environments";
import * as core from "../../../../core";
import * as Flagright from "../../..";
import * as serializers from "../../../../serialization";
import urlJoin from "url-join";
import * as errors from "../../../../errors";

export declare namespace BusinessUsers {
interface Options {
environment?: core.Supplier<environments.FlagrightEnvironment | string>;
apiKey: core.Supplier<string>;
}

interface RequestOptions {
timeoutInSeconds?: number;
}
}

export class BusinessUsers {
constructor(protected readonly _options: BusinessUsers.Options) {}

/**
* ## POST Business User
*
* `/business/user` endpoint allows you to operate on the [Business user entity.](https://docs.flagright.com/docs/flagright-api/8c06ae6a3231a-entities-and-relationships#user)
*
* In order to pass the payload of a User to Flagright and verify the User, you will need to call this endpoint with the User payload. Not all fields are mandatory, you will only need to pass in the fields that you have and are relevant for your compliance setup.
*
* ### Payload
*
*
* Each consumer Business entity needs three mandatory fields:
*
* * `userId` - Unique identifier for the user
* * `legalEntity` - Details of the business legal entity (CompanyGeneralDetails, FinancialDetails etc) - only `legalName`in `CompanyGeneralDetails` is mandatory
* * `createdTimestamp` - UNIX timestamp in *milliseconds* for when the User is created in your system
* @throws {@link Flagright.BadRequestError}
* @throws {@link Flagright.UnauthorizedError}
* @throws {@link Flagright.TooManyRequestsError}
*/
public async create(
request: Flagright.Business,
requestOptions?: BusinessUsers.RequestOptions
): Promise<Flagright.BusinessUsersCreateResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.FlagrightEnvironment.Default,
"business/users"
),
method: "POST",
headers: {
"x-api-key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "flagright",
"X-Fern-SDK-Version": "0.1.0",
},
contentType: "application/json",
body: await serializers.Business.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
});
if (_response.ok) {
return await serializers.BusinessUsersCreateResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 400:
throw new Flagright.BadRequestError(_response.error.body);
case 401:
throw new Flagright.UnauthorizedError(_response.error.body);
case 429:
throw new Flagright.TooManyRequestsError(_response.error.body);
default:
throw new errors.FlagrightError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}

switch (_response.error.reason) {
case "non-json":
throw new errors.FlagrightError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.FlagrightTimeoutError();
case "unknown":
throw new errors.FlagrightError({
message: _response.error.errorMessage,
});
}
}

/**
* ### GET Business User
*
* `/business/user` endpoint allows you to operate on the [Business User entity](https://docs.flagright.com/docs/flagright-api/8c06ae6a3231a-entities-and-relationships#user).
*
* Calling `GET /business/user/{userId}` will return the entire User payload and rule execution results for the User with the corresponding `userId`
* @throws {@link Flagright.UnauthorizedError}
* @throws {@link Flagright.TooManyRequestsError}
*/
public async get(
userId: string,
requestOptions?: BusinessUsers.RequestOptions
): Promise<Flagright.BusinessResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.FlagrightEnvironment.Default,
`business/users/${userId}`
),
method: "GET",
headers: {
"x-api-key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "flagright",
"X-Fern-SDK-Version": "0.1.0",
},
contentType: "application/json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
});
if (_response.ok) {
return await serializers.BusinessResponse.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
switch (_response.error.statusCode) {
case 401:
throw new Flagright.UnauthorizedError(_response.error.body);
case 429:
throw new Flagright.TooManyRequestsError(_response.error.body);
default:
throw new errors.FlagrightError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
}

switch (_response.error.reason) {
case "non-json":
throw new errors.FlagrightError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.FlagrightTimeoutError();
case "unknown":
throw new errors.FlagrightError({
message: _response.error.errorMessage,
});
}
}
}
1 change: 1 addition & 0 deletions src/api/resources/businessUsers/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions src/api/resources/businessUsers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./client";
Loading

0 comments on commit bd7a4f5

Please sign in to comment.