-
Notifications
You must be signed in to change notification settings - Fork 11
feat: initialization #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2f0303b
chore(tsconfig): update compiler options and paths
Convly 29a2c0b
docs(README): update SDK usage for JavaScript/TypeScript projects
Convly 9bf822b
test(jest): configure coverage thresholds and ignore patterns
Convly ade6270
chore(commitlint): reorder import statements
Convly 90a1fdb
chore(git): update ignore files for compressed and config dirs
Convly d74ef5e
chore(eslint): migrate config to mjs module format
Convly 6919606
chore(scripts): add pre-pack script for checks and build
Convly 0ab754c
feat(auth): add base types and abstract class for providers
Convly 17073b4
feat(auth): add new API-token and users-permissions providers
Convly fd37281
feat(auth): add authentication provider factory with type definitions
Convly 8cbe76f
feat(auth): add authentication manager with strategy support
Convly 7d7a185
feat(validators): add URL and SDK validation components
Convly 711f3ba
feat(http): add initial HttpClient implementation with auth and url v…
Convly 0dcb4f2
feat(sdk): implement Strapi SDK
Convly 3cd4bb6
test: add unit tests for full coverage
Convly 61a10e0
Merge branch 'main' of github.com:strapi/sdk-js into feat/sdk-initial…
Convly e611b87
chore(workflows): fix style
Convly 82f37b6
test(sdk): remove initialization tests and refactor url validation tests
Convly 9f0ffce
chore(url): remove protocol validation logic
Convly f20fd14
fix: pr review typos, always prepend api to baseurl and make package …
jhoward1994 935d16f
fix: expect content api url as baseurl
jhoward1994 711e9ea
chore: revert type module
jhoward1994 ad8fb94
chore: mark users and permissions auth as experimental
jhoward1994 6b45bc9
Merge pull request #8 from strapi/fix/module-imports
Convly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ $RECYCLE.BIN/ | |
*.jar | ||
*.rar | ||
*.tar | ||
*.tgz | ||
*.zip | ||
*.com | ||
*.class | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
bin | ||
dist | ||
.github | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pluginEslintImport from 'eslint-plugin-import'; | ||
import pluginTypescriptEslint from '@typescript-eslint/eslint-plugin'; | ||
import tsParser from '@typescript-eslint/parser'; | ||
|
||
export default { | ||
languageOptions: { | ||
parser: tsParser, | ||
parserOptions: { | ||
project: ['./tsconfig.eslint.json'], | ||
}, | ||
}, | ||
files: ['{src,tests}/**/*.{js,ts,jsx,tsx,yml,yaml}'], | ||
plugins: { | ||
'@typescript-eslint': pluginTypescriptEslint, | ||
import: pluginEslintImport, | ||
}, | ||
rules: { | ||
// Use the TypeScript port of 'no-unused-vars' to prevent false positives on abstract methods parameters | ||
// while keeping consistency with TS native behavior of ignoring parameters starting with '_'. | ||
// https://typescript-eslint.io/rules/no-unused-vars/ | ||
'no-unused-vars': 'off', | ||
'@typescript-eslint/no-unused-vars': [ | ||
'error', | ||
{ | ||
args: 'all', | ||
argsIgnorePattern: '^_', | ||
caughtErrors: 'all', | ||
caughtErrorsIgnorePattern: '^_', | ||
destructuredArrayIgnorePattern: '^_', | ||
varsIgnorePattern: '^_', | ||
ignoreRestSiblings: true, | ||
}, | ||
], | ||
|
||
// eslint-plugin-import | ||
'import/no-default-export': 'error', | ||
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'], | ||
'import/first': ['error'], | ||
'import/exports-last': ['error'], | ||
'import/order': [ | ||
'error', | ||
{ | ||
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'], | ||
'newlines-between': 'always', | ||
alphabetize: { order: 'asc', caseInsensitive: true }, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} **/ | ||
module.exports = { | ||
rootDir: '.', | ||
testEnvironment: 'node', | ||
testMatch: ['<rootDir>/tests/unit/**/*.test.ts'], | ||
transform: { | ||
'^.+.tsx?$': ['ts-jest', {}], | ||
}, | ||
coverageDirectory: '<rootDir>/.coverage/', | ||
coveragePathIgnorePatterns: ['/node_modules/', '/tests/'], | ||
coverageThreshold: { | ||
global: { | ||
branches: 95, | ||
functions: 95, | ||
lines: 95, | ||
statements: 95, | ||
}, | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
# Run the Prettier check | ||
pnpm prettier:check && | ||
|
||
# Run linting | ||
pnpm lint && | ||
|
||
# Run TypeScript type check | ||
pnpm ts:check && | ||
|
||
# Run tests with coverage | ||
pnpm test:cov && | ||
|
||
# Run the clean build | ||
pnpm build:clean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { StrapiSDKError } from '../../errors'; | ||
|
||
import type { AuthProviderCreator, AuthProviderMap, CreateAuthProviderParams } from './types'; | ||
import type { AuthProvider } from '../providers'; | ||
|
||
/** | ||
* A factory class responsible for creating and managing authentication providers. | ||
* | ||
* It facilitates the registration and creation of different authentication | ||
* strategies which implement the AuthProvider interface. | ||
* | ||
* @template T_Providers Defines a map for authentication strategy names to their corresponding creator functions. | ||
*/ | ||
export class AuthProviderFactory<T_Providers extends AuthProviderMap = {}> { | ||
private readonly _registry = new Map<StringKeysOf<T_Providers>, AuthProviderCreator>(); | ||
|
||
/** | ||
* Creates an instance of an authentication provider based on the specified strategy. | ||
* | ||
* @param authStrategy The authentication strategy name to be used for creating the provider. | ||
* @param options Configuration options required to initialize the authentication provider. | ||
* | ||
* @returns An instance of an AuthProvider initialized with the given options. | ||
* | ||
* @throws {StrapiSDKError} Throws an error if the specified strategy is not registered in the factory. | ||
* | ||
* @example | ||
* ```typescript | ||
* const factory = new AuthProviderFactory(); | ||
* | ||
* factory.register( | ||
* 'api-token', | ||
* (options: ApiTokenAuthProviderOptions) => new ApiTokenAuthProvider(options) | ||
* ); | ||
* | ||
* const provider = factory.create('api-token', { jwt: 'token' }); | ||
* ``` | ||
*/ | ||
create<T_Strategy extends StringKeysOf<T_Providers> | string>( | ||
authStrategy: T_Strategy, | ||
options: CreateAuthProviderParams<T_Providers, T_Strategy> | ||
): AuthProvider { | ||
const creator = this._registry.get(authStrategy); | ||
|
||
if (!creator) { | ||
throw new StrapiSDKError(`Auth strategy "${authStrategy}" is not supported.`); | ||
} | ||
|
||
return creator(options); | ||
} | ||
|
||
/** | ||
* Registers a new authentication strategy with the factory. | ||
* | ||
* @param strategy The name of the authentication strategy to register. | ||
* @param creator A function that creates an instance of an authentication provider for the specified strategy. | ||
* | ||
* @returns The instance of AuthProviderFactory, for chaining purpose. | ||
* | ||
* @example | ||
* ```typescript | ||
* const factory = new AuthProviderFactory(); | ||
* | ||
* factory | ||
* .register( | ||
* 'api-token', | ||
* (options: ApiTokenAuthProviderOptions) => new ApiTokenAuthProvider(options) | ||
* ) | ||
* .register( | ||
* 'users-permissions', | ||
* (options: UsersPermissionsAuthProviderOptions) => new UsersPermissionsAuthProvider(options) | ||
* ); | ||
* ``` | ||
*/ | ||
register<T_Strategy extends string, T_Creator extends AuthProviderCreator>( | ||
strategy: T_Strategy, | ||
creator: T_Creator | ||
) { | ||
this._registry.set(strategy, creator); | ||
|
||
return this as AuthProviderFactory<T_Providers & { [key in T_Strategy]: typeof creator }>; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './factory'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { AuthProvider } from '../providers'; | ||
|
||
export type AuthProviderCreator<T = any> = (options: T) => AuthProvider; | ||
|
||
export type AuthProviderMap = { [key: string]: AuthProviderCreator }; | ||
|
||
export type CreateAuthProviderParams< | ||
T_Providers extends AuthProviderMap, | ||
T_Strategy extends StringKeysOf<T_Providers>, | ||
> = T_Providers[T_Strategy] extends AuthProviderCreator<infer T_Options> ? T_Options : unknown; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './providers'; | ||
export * from './factory'; | ||
|
||
export * from './manager'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.