Skip to content

Commit

Permalink
chore: Change folder structure (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirgur authored Jul 9, 2024
1 parent eaf7e98 commit 278e00d
Show file tree
Hide file tree
Showing 483 changed files with 859 additions and 1,700 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
The Descope JS repo is composed of many npm packages that are used in Descope SDKs
You can read more on the [Descope Website](https://descope.com).

## Packages
## Folder structure

Descope provides few packages listed bellow.
Please refer to the README and instructions of those SDKs for more detailed information.
This repository hosts multiple packages, located in the `./packages` directory, organized as follows:

- [core-js-sdk](/packages/core-js-sdk): Core SDK. Function that abstract http API usage.
- [web-js-sdk](/packages/web-js-sdk): Web SDK. an SDK for browser usage.
- [web-component](/packages/web-component): Web component. Exposes HTML [web components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) such as Descope flow.
- ./widgets
- ./sdks
- ./libs

For more detailed information, please consult the README and the specific instructions provided for each package.

## Contribution

Expand Down
2 changes: 1 addition & 1 deletion packages/libs/sdk-component-drivers/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdk-component-drivers",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/sdk-component-drivers/src",
"sourceRoot": "packages/libs/sdk-component-drivers/src",
"projectType": "library",
"targets": {
"version": {
Expand Down
2 changes: 1 addition & 1 deletion packages/libs/sdk-helpers/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdk-helpers",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/sdk-helpers/src",
"sourceRoot": "packages/libs/sdk-helpers/src",
"projectType": "library",
"targets": {
"version": {
Expand Down
2 changes: 1 addition & 1 deletion packages/libs/sdk-mixins/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sdk-mixins",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/sdk-mixins/src",
"sourceRoot": "packages/libs/sdk-mixins/src",
"projectType": "library",
"targets": {
"version": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "@descope/core-js-sdk",
"version": "2.23.1",
"author": "Descope Team <[email protected]>",
"homepage": "https://github.com/descope/core-js-sdk",
"homepage": "https://github.com/descope/descope-js",
"bugs": {
"url": "https://github.com/descope/core-js-sdk/issues",
"url": "https://github.com/descope/descope-js/issues",
"email": "[email protected]"
},
"main": "dist/cjs/index.cjs.js",
Expand All @@ -30,7 +30,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/descope/core-js-sdk.git"
"url": "https://github.com/descope/descope-js.git"
},
"files": [
"dist"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "core-js-sdk",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/core-js-sdk/src",
"sourceRoot": "packages/sdks/core-js-sdk/src",
"projectType": "library",
"targets": {
"version": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function cjsPackage() {
buildEnd: () => {
fs.writeFileSync(
'./dist/cjs/package.json',
JSON.stringify({ type: 'commonjs' })
JSON.stringify({ type: 'commonjs' }),
);
},
};
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const httpLogBuilder = () => {
build() {
return Object.keys(msg)
.flatMap((key) =>
msg[key] ? [`${key !== 'Title' ? `${key}: ` : ''}${msg[key]}`] : []
msg[key] ? [`${key !== 'Title' ? `${key}: ` : ''}${msg[key]}`] : [],
)
.join('\n');
},
Expand Down Expand Up @@ -108,14 +108,14 @@ const createFetchLogger = (logger: Logger, receivedFetch?: Fetch) => {
if (!fetchInternal)
// eslint-disable-next-line no-console
logger?.warn(
'Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally'
'Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally',
);

if (!logger) return fetchInternal;
return async (...args: Parameters<Fetch>) => {
if (!fetchInternal)
throw Error(
'Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally'
'Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally',
);
logger.log(buildRequestLog(args));
const resp = await fetchInternal(...args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const mergeHeaders = (...sources: HeadersInit[]) =>
}, acc);

return acc;
}, {})
}, {}),
);

/** Serialize the body to JSON */
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const loginIdValidations = stringNonEmpty('loginId');
export const withVerifyValidations = withValidations(stringNonEmpty('token'));
export const withSignValidations = withValidations(loginIdValidations);
export const withWaitForSessionValidations = withValidations(
stringNonEmpty('pendingRef')
stringNonEmpty('pendingRef'),
);
export const withUpdatePhoneValidations = withValidations(
loginIdValidations,
stringPhone('phone')
stringPhone('phone'),
);
export const withUpdateEmailValidations = withValidations(
loginIdValidations,
stringEmail('email')
stringEmail('email'),
);
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import {
withUpdatePhoneValidations,
} from './validations';

const deliveryMethods = Object.keys(DeliveryMethods).filter(d => d !== DeliveryPhone.voice);
const deliveryMethods = Object.keys(DeliveryMethods).filter(
(d) => d !== DeliveryPhone.voice,
);

const withMagicLink = (httpClient: HttpClient) => ({
verify: withVerifyValidations(
Expand Down Expand Up @@ -107,28 +109,30 @@ const withMagicLink = (httpClient: HttpClient) => ({
),
),
),
phone: Object.keys(DeliveryPhone).filter(d => d !== DeliveryPhone.voice).reduce(
(acc, delivery) => ({
...acc,
[delivery]: withUpdatePhoneValidations(
<T extends boolean>(
loginId: string,
phone: string,
URI?: string,
token?: string,
updateOptions?: UpdateOptions<T>,
) =>
transformResponse(
httpClient.post(
pathJoin(apiPaths.magicLink.update.phone, delivery),
{ loginId, phone, URI, ...updateOptions },
{ token },
phone: Object.keys(DeliveryPhone)
.filter((d) => d !== DeliveryPhone.voice)
.reduce(
(acc, delivery) => ({
...acc,
[delivery]: withUpdatePhoneValidations(
<T extends boolean>(
loginId: string,
phone: string,
URI?: string,
token?: string,
updateOptions?: UpdateOptions<T>,
) =>
transformResponse(
httpClient.post(
pathJoin(apiPaths.magicLink.update.phone, delivery),
{ loginId, phone, URI, ...updateOptions },
{ token },
),
),
),
),
}),
{},
) as MagicLink[Routes.updatePhone],
),
}),
{},
) as MagicLink[Routes.updatePhone],
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const loginIdValidations = stringNonEmpty('loginId');
export const withVerifyValidations = withValidations(stringNonEmpty('token'));
export const withSignValidations = withValidations(loginIdValidations);
export const withWaitForSessionValidations = withValidations(
stringNonEmpty('pendingRef')
stringNonEmpty('pendingRef'),
);
export const withUpdatePhoneValidations = withValidations(
loginIdValidations,
stringPhone('phone')
stringPhone('phone'),
);
export const withUpdateEmailValidations = withValidations(
loginIdValidations,
stringEmail('email')
stringEmail('email'),
);
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type VerifyFn = (code: string) => Promise<SdkResponse<JWTResponse>>;
export type StartFn = (
redirectURL?: string,
loginOptions?: LoginOptions,
token?: string
token?: string,
) => Promise<SdkResponse<URLResponse>>;

export type Providers<T> = Record<keyof typeof OAuthProviders, T>;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const loginIdValidation = stringNonEmpty('loginId');
const newPasswordValidation = stringNonEmpty('newPassword');
export const withSignValidations = withValidations(
loginIdValidation,
stringNonEmpty('password')
stringNonEmpty('password'),
);
export const withSendResetValidations = withValidations(loginIdValidation);
export const withUpdateValidation = withValidations(
loginIdValidation,
newPasswordValidation
newPasswordValidation,
);
export const withReplaceValidation = withValidations(
loginIdValidation,
stringNonEmpty('oldPassword'),
newPasswordValidation
newPasswordValidation,
);
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ const withSaml = (httpClient: HttpClient) => ({
tenantIdOrEmail: string,
redirectUrl?: string,
loginOptions?: LoginOptions,
token?: string
token?: string,
): Promise<SdkResponse<URLResponse>> =>
transformResponse(
httpClient.post(apiPaths.saml.start, loginOptions || {}, {
queryParams: { tenant: tenantIdOrEmail, redirectURL: redirectUrl },
token,
})
)
}),
),
),
exchange: withExchangeValidations(
(code: string): Promise<SdkResponse<JWTResponse>> =>
transformResponse(httpClient.post(apiPaths.saml.exchange, { code }))
transformResponse(httpClient.post(apiPaths.saml.exchange, { code })),
),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { stringNonEmpty, withValidations } from './validations';
const loginIdValidations = stringNonEmpty('loginId');
const withVerifyValidations = withValidations(
loginIdValidations,
stringNonEmpty('code')
stringNonEmpty('code'),
);
const withSignUpValidations = withValidations(loginIdValidations);
const withUpdateValidations = withValidations(loginIdValidations);
Expand All @@ -22,31 +22,31 @@ const withTotp = (httpClient: HttpClient) => ({
signUp: withSignUpValidations(
(loginId: string, user?: User): Promise<SdkResponse<TOTPResponse>> =>
transformResponse(
httpClient.post(apiPaths.totp.signUp, { loginId, user })
)
httpClient.post(apiPaths.totp.signUp, { loginId, user }),
),
),

verify: withVerifyValidations(
(
loginId: string,
code: string,
loginOptions?: LoginOptions,
token?: string
token?: string,
): Promise<SdkResponse<JWTResponse>> =>
transformResponse(
httpClient.post(
apiPaths.totp.verify,
{ loginId, code, loginOptions },
{ token }
)
)
{ token },
),
),
),

update: withUpdateValidations(
(loginId: string, token?: string): Promise<SdkResponse<TOTPResponse>> =>
transformResponse(
httpClient.post(apiPaths.totp.update, { loginId }, { token })
)
httpClient.post(apiPaths.totp.update, { loginId }, { token }),
),
),
});

Expand Down
File renamed without changes.
Loading

0 comments on commit 278e00d

Please sign in to comment.