nanosaas 0.1.0-beta.1 → 0.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/common/config/index.d.ts +2 -0
- package/dist/common/config/index.js +7 -0
- package/dist/common/config/index.mjs +6 -0
- package/dist/modules/authentication/use-cases/register.use-case.js +2 -1
- package/dist/modules/authentication/use-cases/register.use-case.mjs +2 -1
- package/docs/getting-started.md +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.2
|
|
4
|
+
|
|
5
|
+
- `personalOrganization` setting (`configure`, or `<PREFIX>_PERSONAL_ORGANIZATION=false` in the environment or in a tenant context). When off, `register` creates only the user. For databases whose users are not members of an organization, like the end users of a tenant.
|
|
6
|
+
|
|
3
7
|
## 0.1.0-beta.0
|
|
4
8
|
|
|
5
9
|
Architecture decisions taken before the first publication: organizations first (every user has a personal organization and tenant data always has `organizationId`), email as the only identity of the core, neutral billing names (`platform`, `externalId`), open registries for platforms, roles, services and activity types, enums for statuses, error messages and collections, `payload` for the body in every function, signing keys with `kid` and access tokens without personal data, and an extension registry plus a `properties` bag in every entity.
|
|
@@ -16,6 +16,7 @@ export interface NanosaasConfig {
|
|
|
16
16
|
supportedLanguages?: string[];
|
|
17
17
|
defaultLanguage?: string;
|
|
18
18
|
membershipCacheTtlSeconds?: number;
|
|
19
|
+
personalOrganization?: boolean;
|
|
19
20
|
}
|
|
20
21
|
export declare const DEFAULT_APP_NAME = "nanosaas";
|
|
21
22
|
export declare const DEFAULT_LANGUAGE = "en";
|
|
@@ -34,6 +35,7 @@ export declare const getApiBaseUrl: () => string;
|
|
|
34
35
|
export declare const getDefaultLanguage: () => string;
|
|
35
36
|
export declare const getSupportedLanguages: () => string[];
|
|
36
37
|
export declare const getMembershipCacheTtlSeconds: () => number;
|
|
38
|
+
export declare const getPersonalOrganization: () => boolean;
|
|
37
39
|
export declare const getCollectionPrefix: () => string;
|
|
38
40
|
export declare const getConfiguredEncryptionKeys: () => Record<string, string | {
|
|
39
41
|
material: string;
|
|
@@ -34,6 +34,7 @@ __export(config_exports, {
|
|
|
34
34
|
getDefaultLanguage: () => getDefaultLanguage,
|
|
35
35
|
getEnvPrefix: () => getEnvPrefix,
|
|
36
36
|
getMembershipCacheTtlSeconds: () => getMembershipCacheTtlSeconds,
|
|
37
|
+
getPersonalOrganization: () => getPersonalOrganization,
|
|
37
38
|
getSupportedLanguages: () => getSupportedLanguages,
|
|
38
39
|
getTokenIssuer: () => getTokenIssuer,
|
|
39
40
|
getTokenKeyVersion: () => getTokenKeyVersion,
|
|
@@ -70,6 +71,11 @@ const getApiBaseUrl = () => (resolve("API_BASE_URL", current.apiBaseUrl) ?? "").
|
|
|
70
71
|
const getDefaultLanguage = () => current.defaultLanguage || DEFAULT_LANGUAGE;
|
|
71
72
|
const getSupportedLanguages = () => current.supportedLanguages?.length ? current.supportedLanguages : [getDefaultLanguage()];
|
|
72
73
|
const getMembershipCacheTtlSeconds = () => current.membershipCacheTtlSeconds ?? DEFAULT_MEMBERSHIP_CACHE_TTL_SECONDS;
|
|
74
|
+
const getPersonalOrganization = () => {
|
|
75
|
+
const value = resolve("PERSONAL_ORGANIZATION");
|
|
76
|
+
if (value !== void 0) return value.trim().toLowerCase() !== "false";
|
|
77
|
+
return current.personalOrganization ?? true;
|
|
78
|
+
};
|
|
73
79
|
const COLLECTION_PREFIX = /^[A-Za-z0-9_]*$/;
|
|
74
80
|
const getCollectionPrefix = () => {
|
|
75
81
|
const prefix = resolve("COLLECTION_PREFIX", current.collectionPrefix) ?? "";
|
|
@@ -97,6 +103,7 @@ const getAllowPlaintext = () => current.allowPlaintext === true;
|
|
|
97
103
|
getDefaultLanguage,
|
|
98
104
|
getEnvPrefix,
|
|
99
105
|
getMembershipCacheTtlSeconds,
|
|
106
|
+
getPersonalOrganization,
|
|
100
107
|
getSupportedLanguages,
|
|
101
108
|
getTokenIssuer,
|
|
102
109
|
getTokenKeyVersion,
|
|
@@ -27,6 +27,11 @@ const getApiBaseUrl = () => (resolve("API_BASE_URL", current.apiBaseUrl) ?? "").
|
|
|
27
27
|
const getDefaultLanguage = () => current.defaultLanguage || DEFAULT_LANGUAGE;
|
|
28
28
|
const getSupportedLanguages = () => current.supportedLanguages?.length ? current.supportedLanguages : [getDefaultLanguage()];
|
|
29
29
|
const getMembershipCacheTtlSeconds = () => current.membershipCacheTtlSeconds ?? DEFAULT_MEMBERSHIP_CACHE_TTL_SECONDS;
|
|
30
|
+
const getPersonalOrganization = () => {
|
|
31
|
+
const value = resolve("PERSONAL_ORGANIZATION");
|
|
32
|
+
if (value !== void 0) return value.trim().toLowerCase() !== "false";
|
|
33
|
+
return current.personalOrganization ?? true;
|
|
34
|
+
};
|
|
30
35
|
const COLLECTION_PREFIX = /^[A-Za-z0-9_]*$/;
|
|
31
36
|
const getCollectionPrefix = () => {
|
|
32
37
|
const prefix = resolve("COLLECTION_PREFIX", current.collectionPrefix) ?? "";
|
|
@@ -53,6 +58,7 @@ export {
|
|
|
53
58
|
getDefaultLanguage,
|
|
54
59
|
getEnvPrefix,
|
|
55
60
|
getMembershipCacheTtlSeconds,
|
|
61
|
+
getPersonalOrganization,
|
|
56
62
|
getSupportedLanguages,
|
|
57
63
|
getTokenIssuer,
|
|
58
64
|
getTokenKeyVersion,
|
|
@@ -22,6 +22,7 @@ __export(register_use_case_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(register_use_case_exports);
|
|
24
24
|
var import_base = require("../../../common/base/base.use-case.js");
|
|
25
|
+
var import_config = require("../../../common/config/index.js");
|
|
25
26
|
var import_db = require("../../../common/db/index.js");
|
|
26
27
|
var import_events = require("../../../common/events/index.js");
|
|
27
28
|
var import_rate_limit = require("../../../common/rate-limit/index.js");
|
|
@@ -68,7 +69,7 @@ class RegisterUseCase extends import_base.BaseUseCase {
|
|
|
68
69
|
if (await this.userRepository.findByEmailWithPassword(email, scope)) this.throwHttpError({ statusCode: import_error.HttpStatus.CONFLICT, errorMessage: import_error.ErrorMessage.EMAIL_ALREADY_REGISTERED });
|
|
69
70
|
const allowed = (0, import_extension_registry.omitPaths)(payload, [...import_extension_registry.CONTROL_FIELDS, "role", "properties", ...import_user_extensions.userExtensions.protectedPaths()]);
|
|
70
71
|
const user = await this.createUser.execute({ payload: { ...allowed, preferences: (0, import_default_preferences.withDefaultPreferences)(allowed.preferences, params.requestContext?.situation) }, scope });
|
|
71
|
-
await this.ensurePersonalOrganization.execute({ actor: import_actor.Actor.fromClaims({ userId: String(user._id) }).withProfile(user) });
|
|
72
|
+
if ((0, import_config.getPersonalOrganization)()) await this.ensurePersonalOrganization.execute({ actor: import_actor.Actor.fromClaims({ userId: String(user._id) }).withProfile(user) });
|
|
72
73
|
await this.events.publish({ type: import_auth_events.AuthEventType.USER_REGISTERED, payload: { userId: String(user._id), ipAddress } });
|
|
73
74
|
return this.login.execute({ payload: { email, password }, ipAddress });
|
|
74
75
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseUseCase } from "../../../common/base/base.use-case.js";
|
|
2
|
+
import { getPersonalOrganization } from "../../../common/config/index.js";
|
|
2
3
|
import { Scope } from "../../../common/db/index.js";
|
|
3
4
|
import { eventBus } from "../../../common/events/index.js";
|
|
4
5
|
import { defaultRateLimitRules, RateLimiter, RateLimitScope, rateLimitKey } from "../../../common/rate-limit/index.js";
|
|
@@ -45,7 +46,7 @@ class RegisterUseCase extends BaseUseCase {
|
|
|
45
46
|
if (await this.userRepository.findByEmailWithPassword(email, scope)) this.throwHttpError({ statusCode: HttpStatus.CONFLICT, errorMessage: ErrorMessage.EMAIL_ALREADY_REGISTERED });
|
|
46
47
|
const allowed = omitPaths(payload, [...CONTROL_FIELDS, "role", "properties", ...userExtensions.protectedPaths()]);
|
|
47
48
|
const user = await this.createUser.execute({ payload: { ...allowed, preferences: withDefaultPreferences(allowed.preferences, params.requestContext?.situation) }, scope });
|
|
48
|
-
await this.ensurePersonalOrganization.execute({ actor: Actor.fromClaims({ userId: String(user._id) }).withProfile(user) });
|
|
49
|
+
if (getPersonalOrganization()) await this.ensurePersonalOrganization.execute({ actor: Actor.fromClaims({ userId: String(user._id) }).withProfile(user) });
|
|
49
50
|
await this.events.publish({ type: AuthEventType.USER_REGISTERED, payload: { userId: String(user._id), ipAddress } });
|
|
50
51
|
return this.login.execute({ payload: { email, password }, ipAddress });
|
|
51
52
|
}
|
package/docs/getting-started.md
CHANGED
|
@@ -17,6 +17,8 @@ Secrets: `JWT_SECRET` (key version 1) and `JWT_SECRET_V<n>` for rotation. Set `t
|
|
|
17
17
|
|
|
18
18
|
The master keys of the encryption are variables of the process, `<PREFIX>_ENCRYPTION_KEY_V1` and so on (see [encryption](encryption.md)). Nothing loads `.env` for you: do it in your app.
|
|
19
19
|
|
|
20
|
+
`register` creates a personal organization for every new user. If the users of your database are not members of any organization (the end users of a tenant, for example), set `personalOrganization: false` in `configure`, or `<PREFIX>_PERSONAL_ORGANIZATION=false` in the environment or in a tenant context.
|
|
21
|
+
|
|
20
22
|
## Collection names
|
|
21
23
|
|
|
22
24
|
Every collection of the package has one standard name (`users`, `refresh_tokens`, `organizations`, `memberships`, `invitations`, `billing_accounts`, `billing_transactions`, `subscriptions`, `integrations`, `activities`, `rate_limits`, `oauth_states`, `revoked_tokens`), the same in every product. There is no per collection name: a name you already use is renamed in your migration, not configured. The only setting is `collectionPrefix` (empty by default, `<PREFIX>_COLLECTION_PREFIX` in the environment or in a tenant context), for a solution that shares its database with something else. It applies to the collections of the package and never to the ones of the app that use `MongoRepository`; the specs of the indexes are written with the standard names and `ensureIndexes` adds the prefix.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nanosaas",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"description": "Core framework for multitenant SaaS backends: users, authentication, organizations, billing, OAuth integrations and a scoped MongoDB repository, as ready to use functions",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jose Barcos",
|