@formbricks/api
Advanced tools
Comparing version 0.1.0 to 1.0.0
@@ -1,93 +0,2 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/lib.ts | ||
var _errors = require('@formbricks/errors'); | ||
// src/endpoints/response.ts | ||
var createResponse = async (request, options) => { | ||
const result = await request( | ||
`/api/v1/client/environments/${options.environmentId}/responses`, | ||
{ | ||
surveyId: options.surveyId, | ||
personId: options.personId, | ||
response: { | ||
data: options.data, | ||
finished: options.finished || false | ||
} | ||
}, | ||
{ method: "POST" } | ||
); | ||
return result; | ||
}; | ||
var updateResponse = async (request, options) => { | ||
const result = await request( | ||
`/api/v1/client/environments/${options.environmentId}/responses/${options.responseId}`, | ||
{ | ||
response: { | ||
data: options.data, | ||
finished: options.finished || false | ||
} | ||
}, | ||
{ | ||
method: "PUT" | ||
} | ||
); | ||
if (result.ok === false) | ||
return result; | ||
const newResponse = { | ||
...result.data, | ||
createdAt: new Date(result.data.createdAt), | ||
updatedAt: new Date(result.data.updatedAt) | ||
}; | ||
return _errors.ok.call(void 0, newResponse); | ||
}; | ||
// src/lib.ts | ||
var FormbricksAPI = class { | ||
constructor(options) { | ||
this.baseUrl = options.apiHost || "https://app.formbricks.com"; | ||
this.environmentId = options.environmentId; | ||
this.request = this.request.bind(this); | ||
} | ||
async createResponse(options) { | ||
return this.runWithEnvironmentId(createResponse, options); | ||
} | ||
async updateResponse(options) { | ||
return this.runWithEnvironmentId(updateResponse, options); | ||
} | ||
/* | ||
This was added to reduce code duplication | ||
It checks that the function passed has the environmentId in the Options type | ||
and automatically adds it to the options | ||
*/ | ||
runWithEnvironmentId(fn, options) { | ||
const newOptions = { environmentId: this.environmentId, ...options }; | ||
return fn(this.request, newOptions); | ||
} | ||
async request(path, data, options) { | ||
const url = new URL(path, this.baseUrl); | ||
const headers = { | ||
"Content-Type": "application/json" | ||
}; | ||
const body = JSON.stringify(data); | ||
const res = _errors.wrapThrows.call(void 0, fetch)(url, { headers, body, ...options }); | ||
if (res.ok === false) | ||
return _errors.err.call(void 0, res.error); | ||
const response = await res.data; | ||
const resJson = await response.json(); | ||
if (!response.ok) { | ||
return _errors.err.call(void 0, { | ||
code: "network_error", | ||
message: response.statusText, | ||
status: response.status, | ||
url | ||
}); | ||
} | ||
return _errors.ok.call(void 0, resJson); | ||
} | ||
}; | ||
exports.FormbricksAPI = FormbricksAPI; exports.default = FormbricksAPI; | ||
//# sourceMappingURL=index.js.map | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=s=>({ok:!1,error:s});async function t(t,e,r,a){const o=new URL(e,t),n=JSON.stringify(a),i=(d=fetch,(...s)=>{try{return{ok:!0,data:d(...s)}}catch(t){return{ok:!1,error:t}}})(o.toString(),{method:r,headers:{"Content-Type":"application/json"},body:n});var d;if(!1===i.ok)return s(i.error);const c=await i.data,{data:p}=await c.json();return c.ok?(s=>({ok:!0,data:s}))(p):s({code:"network_error",message:c.statusText,status:c.status,url:o})}class e{constructor(s){this.apiHost=s}async create({surveyId:s,personId:e,finished:r,data:a}){return t(this.apiHost,"/api/v1/client/responses","POST",{surveyId:s,personId:e,finished:r,data:a})}async update({responseId:s,finished:e,data:r}){return t(this.apiHost,`/api/v1/client/responses/${s}`,"PUT",{finished:e,data:r})}}class r{constructor(s){this.apiHost=s}async markDisplayedForPerson({surveyId:s,personId:e}){return t(this.apiHost,"/api/v1/client/displays","POST",{surveyId:s,personId:e})}async markResponded({displayId:s}){return t(this.apiHost,`/api/v1/client/displays/${s}/responded`,"POST")}}class a{constructor(s){const{apiHost:t}=s;this.response=new e(t),this.display=new r(t)}}exports.FormbricksAPI=class{constructor(s){this.client=new a(s)}}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,68 +0,45 @@ | ||
import { Result } from '@formbricks/errors'; | ||
import { NetworkError } from '@formbricks/types/v1/errors'; | ||
import { Result } from '@formbricks/types/v1/errorHandlers'; | ||
import { TDisplay } from '@formbricks/types/v1/displays'; | ||
import { TDisplayInput } from '@formbricks/types/v1/displays'; | ||
import { TResponse } from '@formbricks/types/v1/responses'; | ||
import { TResponseInput } from '@formbricks/types/v1/responses'; | ||
import { TResponseUpdateInput } from '@formbricks/types/v1/responses'; | ||
type NetworkError = { | ||
code: "network_error"; | ||
message: string; | ||
status: number; | ||
url: URL; | ||
}; | ||
declare interface ApiConfig { | ||
environmentId: string; | ||
apiHost: string; | ||
} | ||
// by using Brand, we can check that you can't pass to an environmentId a surveyId | ||
type Brand<T, B> = T & { __brand: B }; | ||
declare class Client { | ||
response: ResponseAPI; | ||
display: DisplayAPI; | ||
constructor(options: ApiConfig); | ||
} | ||
type EnvironmentId = Brand<string, "EnvironmentId">; | ||
type SurveyId = Brand<string, "SurveyId">; | ||
type PersonId = Brand<string, "PersonId">; | ||
type ResponseId = Brand<string, "ResponseId">; | ||
type KeyValueData = { [key: string]: string | number | string[] | number[] | undefined }; | ||
interface CreateResponseResponse { | ||
id: ResponseId; | ||
declare class DisplayAPI { | ||
private apiHost; | ||
constructor(baseUrl: string); | ||
markDisplayedForPerson({ surveyId, personId, }: TDisplayInput): Promise<Result<TDisplay, NetworkError | Error>>; | ||
markResponded({ displayId }: { | ||
displayId: string; | ||
}): Promise<Result<TDisplay, NetworkError | Error>>; | ||
} | ||
interface UpdateResponseResponse { | ||
id: ResponseId; | ||
createdAt: string; | ||
updatedAt: string; | ||
finished: boolean; | ||
surveyId: SurveyId; | ||
personId: PersonId; | ||
data: KeyValueData; | ||
meta: {}; | ||
userAttributes: string[]; | ||
tags: string[]; | ||
} | ||
interface UpdateResponseResponseFormatted extends Omit<UpdateResponseResponse, "createdAt" | "updatedAt"> { | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} | ||
interface CreateResponseOptions { | ||
environmentId: EnvironmentId; | ||
surveyId: SurveyId; | ||
personId?: PersonId; | ||
data: KeyValueData; | ||
finished?: boolean; | ||
export declare class FormbricksAPI { | ||
client: Client; | ||
constructor(options: ApiConfig); | ||
} | ||
interface UpdateResponseOptions { | ||
environmentId: EnvironmentId; | ||
data: KeyValueData; | ||
responseId: ResponseId; | ||
finished?: boolean; | ||
} | ||
interface FormbricksAPIOptions { | ||
apiHost?: string; | ||
environmentId: EnvironmentId; | ||
declare class ResponseAPI { | ||
private apiHost; | ||
constructor(apiHost: string); | ||
create({ surveyId, personId, finished, data, }: TResponseInput): Promise<Result<TResponse, NetworkError | Error>>; | ||
update({ responseId, finished, data, }: TResponseUpdateInputWithResponseId): Promise<Result<TResponse, NetworkError | Error>>; | ||
} | ||
declare class FormbricksAPI { | ||
private readonly baseUrl; | ||
private readonly environmentId; | ||
constructor(options: FormbricksAPIOptions); | ||
createResponse(options: Omit<CreateResponseOptions, "environmentId">): Promise<Result<CreateResponseResponse, NetworkError>>; | ||
updateResponse(options: Omit<UpdateResponseOptions, "environmentId">): Promise<Result<UpdateResponseResponseFormatted, NetworkError>>; | ||
private runWithEnvironmentId; | ||
private request; | ||
} | ||
export { CreateResponseResponse, EnvironmentId, FormbricksAPI, FormbricksAPIOptions, KeyValueData, NetworkError, PersonId, ResponseId, SurveyId, UpdateResponseResponse, UpdateResponseResponseFormatted, FormbricksAPI as default }; | ||
declare type TResponseUpdateInputWithResponseId = TResponseUpdateInput & { | ||
responseId: string; | ||
}; | ||
export { } |
@@ -1,93 +0,2 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/lib.ts | ||
var _errors = require('@formbricks/errors'); | ||
// src/endpoints/response.ts | ||
var createResponse = async (request, options) => { | ||
const result = await request( | ||
`/api/v1/client/environments/${options.environmentId}/responses`, | ||
{ | ||
surveyId: options.surveyId, | ||
personId: options.personId, | ||
response: { | ||
data: options.data, | ||
finished: options.finished || false | ||
} | ||
}, | ||
{ method: "POST" } | ||
); | ||
return result; | ||
}; | ||
var updateResponse = async (request, options) => { | ||
const result = await request( | ||
`/api/v1/client/environments/${options.environmentId}/responses/${options.responseId}`, | ||
{ | ||
response: { | ||
data: options.data, | ||
finished: options.finished || false | ||
} | ||
}, | ||
{ | ||
method: "PUT" | ||
} | ||
); | ||
if (result.ok === false) | ||
return result; | ||
const newResponse = { | ||
...result.data, | ||
createdAt: new Date(result.data.createdAt), | ||
updatedAt: new Date(result.data.updatedAt) | ||
}; | ||
return _errors.ok.call(void 0, newResponse); | ||
}; | ||
// src/lib.ts | ||
var FormbricksAPI = class { | ||
constructor(options) { | ||
this.baseUrl = options.apiHost || "https://app.formbricks.com"; | ||
this.environmentId = options.environmentId; | ||
this.request = this.request.bind(this); | ||
} | ||
async createResponse(options) { | ||
return this.runWithEnvironmentId(createResponse, options); | ||
} | ||
async updateResponse(options) { | ||
return this.runWithEnvironmentId(updateResponse, options); | ||
} | ||
/* | ||
This was added to reduce code duplication | ||
It checks that the function passed has the environmentId in the Options type | ||
and automatically adds it to the options | ||
*/ | ||
runWithEnvironmentId(fn, options) { | ||
const newOptions = { environmentId: this.environmentId, ...options }; | ||
return fn(this.request, newOptions); | ||
} | ||
async request(path, data, options) { | ||
const url = new URL(path, this.baseUrl); | ||
const headers = { | ||
"Content-Type": "application/json" | ||
}; | ||
const body = JSON.stringify(data); | ||
const res = _errors.wrapThrows.call(void 0, fetch)(url, { headers, body, ...options }); | ||
if (res.ok === false) | ||
return _errors.err.call(void 0, res.error); | ||
const response = await res.data; | ||
const resJson = await response.json(); | ||
if (!response.ok) { | ||
return _errors.err.call(void 0, { | ||
code: "network_error", | ||
message: response.statusText, | ||
status: response.status, | ||
url | ||
}); | ||
} | ||
return _errors.ok.call(void 0, resJson); | ||
} | ||
}; | ||
exports.FormbricksAPI = FormbricksAPI; exports.default = FormbricksAPI; | ||
//# sourceMappingURL=index.js.map | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=s=>({ok:!1,error:s});async function t(t,e,r,a){const o=new URL(e,t),n=JSON.stringify(a),i=(d=fetch,(...s)=>{try{return{ok:!0,data:d(...s)}}catch(t){return{ok:!1,error:t}}})(o.toString(),{method:r,headers:{"Content-Type":"application/json"},body:n});var d;if(!1===i.ok)return s(i.error);const c=await i.data,{data:p}=await c.json();return c.ok?(s=>({ok:!0,data:s}))(p):s({code:"network_error",message:c.statusText,status:c.status,url:o})}class e{constructor(s){this.apiHost=s}async create({surveyId:s,personId:e,finished:r,data:a}){return t(this.apiHost,"/api/v1/client/responses","POST",{surveyId:s,personId:e,finished:r,data:a})}async update({responseId:s,finished:e,data:r}){return t(this.apiHost,`/api/v1/client/responses/${s}`,"PUT",{finished:e,data:r})}}class r{constructor(s){this.apiHost=s}async markDisplayedForPerson({surveyId:s,personId:e}){return t(this.apiHost,"/api/v1/client/displays","POST",{surveyId:s,personId:e})}async markResponded({displayId:s}){return t(this.apiHost,`/api/v1/client/displays/${s}/responded`,"POST")}}class a{constructor(s){const{apiHost:t}=s;this.response=new e(t),this.display=new r(t)}}exports.FormbricksAPI=class{constructor(s){this.client=new a(s)}}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@formbricks/api", | ||
"version": "0.1.0", | ||
"description": "A Typescript API-wrapper for managing the Formbricks Client API.", | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"description": "Formbricks-api is an api wrapper for the Formbricks client API", | ||
"keywords": [ | ||
"Formbricks", | ||
"surveys", | ||
"experience management", | ||
"api" | ||
], | ||
"sideEffects": false, | ||
"files": [ | ||
"dist" | ||
], | ||
"source": "./src/index.ts", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"sideEffects": false, | ||
"files": [ | ||
"dist/**" | ||
], | ||
"dependencies": { | ||
"@formbricks/errors": "0.1.0" | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.umd.js" | ||
} | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.41.0", | ||
"rimraf": "^5.0.1", | ||
"tsup": "^6.7.0", | ||
"terser": "^5.21.0", | ||
"vite": "^4.4.11", | ||
"vite-plugin-dts": "^3.6.0", | ||
"@formbricks/types": "0.0.0", | ||
"@formbricks/lib": "0.0.0", | ||
"@formbricks/tsconfig": "1.0.0", | ||
@@ -25,4 +36,5 @@ "eslint-config-formbricks": "1.0.0" | ||
"scripts": { | ||
"build": "tsup", | ||
"dev": "tsup --watch", | ||
"dev": "vite build --watch", | ||
"build": "tsc && vite build", | ||
"go": "vite build --watch", | ||
"lint": "eslint ./src --fix", | ||
@@ -29,0 +41,0 @@ "clean": "rimraf .turbo node_modules dist" |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
75528
0
11
1
7
157
5
- Removed@formbricks/errors@0.1.0
- Removed@formbricks/errors@0.1.0(transitive)