@foxy.io/sdk 1.10.0 → 1.11.1

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.
@@ -26,11 +26,15 @@ AuthError.NEW_PASSWORD_REQUIRED = 'NEW_PASSWORD_REQUIRED';
26
26
  AuthError.INVALID_NEW_PASSWORD = 'INVALID_NEW_PASSWORD';
27
27
  /** Credentials are invalid. That could mean empty or invalid email or password or otherwise incorrect auth data. */
28
28
  AuthError.UNAUTHORIZED = 'UNAUTHORIZED';
29
+ /** Provided form data is invalid, e.g. email is too long or captcha is expired. */
30
+ AuthError.INVALID_FORM = 'INVALID_FORM';
31
+ /** Provided email is already taken. Applies to customer registration only. */
32
+ AuthError.UNAVAILABLE = 'UNAVAILABLE';
29
33
  /** Any other or internal error that interrupted authentication. */
30
34
  AuthError.UNKNOWN = 'UNKNOWN';
31
35
  /** Available class member validators. */
32
36
  AuthError.v8n = {
33
37
  constructor: v8n_1.default().schema({
34
- code: v8n_1.default().passesAnyOf(v8n_1.default().exact(AuthError.NEW_PASSWORD_REQUIRED), v8n_1.default().exact(AuthError.INVALID_NEW_PASSWORD), v8n_1.default().exact(AuthError.UNAUTHORIZED), v8n_1.default().exact(AuthError.UNKNOWN)),
38
+ code: v8n_1.default().passesAnyOf(v8n_1.default().exact(AuthError.NEW_PASSWORD_REQUIRED), v8n_1.default().exact(AuthError.INVALID_NEW_PASSWORD), v8n_1.default().exact(AuthError.UNAUTHORIZED), v8n_1.default().exact(AuthError.INVALID_FORM), v8n_1.default().exact(AuthError.UNAVAILABLE), v8n_1.default().exact(AuthError.UNKNOWN)),
35
39
  }),
36
40
  };
@@ -29,9 +29,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
29
29
  };
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
31
  exports.API = void 0;
32
- const Core = __importStar(require("../core/index.js"));
33
32
  const cross_fetch_1 = require("cross-fetch");
34
33
  const v8n_js_1 = require("../core/v8n.js");
34
+ const Core = __importStar(require("../core/index.js"));
35
35
  /**
36
36
  * Customer API for adding custom functionality to websites and web apps with our Customer Portal.
37
37
  *
@@ -67,6 +67,33 @@ class API extends Core.API {
67
67
  }
68
68
  });
69
69
  }
70
+ /**
71
+ * Creates a new customer account with the given credentials.
72
+ * If the email is already taken, `Core.API.AuthError` with code `UNAVAILABLE` will be thrown.
73
+ * If customer registration is disabled, `Core.API.AuthError` with code `UNAUTHORIZED` will be thrown.
74
+ * If the provided form data is invalid (e.g. captcha is expired), `Core.API.AuthError` with code `INVALID_FORM` will be thrown.
75
+ *
76
+ * @param params Customer information.
77
+ */
78
+ signUp(params) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ API.v8n.signUpParams.check(params);
81
+ const url = new URL('./sign_up', this.base);
82
+ const response = yield this.fetch(url.toString(), {
83
+ method: 'POST',
84
+ body: JSON.stringify(params),
85
+ });
86
+ if (!response.ok) {
87
+ if (response.status === 400)
88
+ throw new Core.API.AuthError({ code: 'INVALID_FORM' });
89
+ if (response.status === 401)
90
+ throw new Core.API.AuthError({ code: 'UNAUTHORIZED' });
91
+ if (response.status === 403)
92
+ throw new Core.API.AuthError({ code: 'UNAVAILABLE' });
93
+ throw new Core.API.AuthError({ code: 'UNKNOWN' });
94
+ }
95
+ });
96
+ }
70
97
  /**
71
98
  * Initiates password reset for a customer with the given email.
72
99
  * If such customer exists, they will receive an email from Foxy with further instructions.
@@ -130,6 +157,16 @@ exports.API = API;
130
157
  API.SESSION = 'session';
131
158
  /** Validators for the method arguments in this class (internal). */
132
159
  API.v8n = Object.assign({}, Core.API.v8n, {
160
+ signUpParams: v8n_js_1.v8n().schema({
161
+ verification: v8n_js_1.v8n().schema({
162
+ token: v8n_js_1.v8n().string(),
163
+ type: v8n_js_1.v8n().passesAnyOf(v8n_js_1.v8n().exact('hcaptcha')),
164
+ }),
165
+ first_name: v8n_js_1.v8n().optional(v8n_js_1.v8n().string().maxLength(50)),
166
+ last_name: v8n_js_1.v8n().optional(v8n_js_1.v8n().string().maxLength(50)),
167
+ password: v8n_js_1.v8n().string().maxLength(50),
168
+ email: v8n_js_1.v8n().string().maxLength(100),
169
+ }),
133
170
  credentials: v8n_js_1.v8n().schema({
134
171
  email: v8n_js_1.v8n().string(),
135
172
  newPassword: v8n_js_1.v8n().optional(v8n_js_1.v8n().string()),
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNextTransactionDateConstraints = void 0;
4
- const getNextTransactionDateConstraints_1 = require("../backend/getNextTransactionDateConstraints");
4
+ const getNextTransactionDateConstraints_js_1 = require("../backend/getNextTransactionDateConstraints.js");
5
5
  /**
6
6
  * Finds which next transaction date modification rules are applicable to
7
7
  * the given subscription and merges them together.
@@ -27,6 +27,6 @@ function getNextTransactionDateConstraints(data, rules) {
27
27
  min: rule.min,
28
28
  }));
29
29
  }
30
- return getNextTransactionDateConstraints_1.getNextTransactionDateConstraints(data, backendRules);
30
+ return getNextTransactionDateConstraints_js_1.getNextTransactionDateConstraints(data, backendRules);
31
31
  }
32
32
  exports.getNextTransactionDateConstraints = getNextTransactionDateConstraints;
@@ -19,11 +19,15 @@ AuthError.NEW_PASSWORD_REQUIRED = 'NEW_PASSWORD_REQUIRED';
19
19
  AuthError.INVALID_NEW_PASSWORD = 'INVALID_NEW_PASSWORD';
20
20
  /** Credentials are invalid. That could mean empty or invalid email or password or otherwise incorrect auth data. */
21
21
  AuthError.UNAUTHORIZED = 'UNAUTHORIZED';
22
+ /** Provided form data is invalid, e.g. email is too long or captcha is expired. */
23
+ AuthError.INVALID_FORM = 'INVALID_FORM';
24
+ /** Provided email is already taken. Applies to customer registration only. */
25
+ AuthError.UNAVAILABLE = 'UNAVAILABLE';
22
26
  /** Any other or internal error that interrupted authentication. */
23
27
  AuthError.UNKNOWN = 'UNKNOWN';
24
28
  /** Available class member validators. */
25
29
  AuthError.v8n = {
26
30
  constructor: v8n().schema({
27
- code: v8n().passesAnyOf(v8n().exact(AuthError.NEW_PASSWORD_REQUIRED), v8n().exact(AuthError.INVALID_NEW_PASSWORD), v8n().exact(AuthError.UNAUTHORIZED), v8n().exact(AuthError.UNKNOWN)),
31
+ code: v8n().passesAnyOf(v8n().exact(AuthError.NEW_PASSWORD_REQUIRED), v8n().exact(AuthError.INVALID_NEW_PASSWORD), v8n().exact(AuthError.UNAUTHORIZED), v8n().exact(AuthError.INVALID_FORM), v8n().exact(AuthError.UNAVAILABLE), v8n().exact(AuthError.UNKNOWN)),
28
32
  }),
29
33
  };
@@ -7,9 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import * as Core from '../core/index.js';
11
10
  import { Request, fetch } from 'cross-fetch';
12
11
  import { v8n } from '../core/v8n.js';
12
+ import * as Core from '../core/index.js';
13
13
  /**
14
14
  * Customer API for adding custom functionality to websites and web apps with our Customer Portal.
15
15
  *
@@ -45,6 +45,33 @@ export class API extends Core.API {
45
45
  }
46
46
  });
47
47
  }
48
+ /**
49
+ * Creates a new customer account with the given credentials.
50
+ * If the email is already taken, `Core.API.AuthError` with code `UNAVAILABLE` will be thrown.
51
+ * If customer registration is disabled, `Core.API.AuthError` with code `UNAUTHORIZED` will be thrown.
52
+ * If the provided form data is invalid (e.g. captcha is expired), `Core.API.AuthError` with code `INVALID_FORM` will be thrown.
53
+ *
54
+ * @param params Customer information.
55
+ */
56
+ signUp(params) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ API.v8n.signUpParams.check(params);
59
+ const url = new URL('./sign_up', this.base);
60
+ const response = yield this.fetch(url.toString(), {
61
+ method: 'POST',
62
+ body: JSON.stringify(params),
63
+ });
64
+ if (!response.ok) {
65
+ if (response.status === 400)
66
+ throw new Core.API.AuthError({ code: 'INVALID_FORM' });
67
+ if (response.status === 401)
68
+ throw new Core.API.AuthError({ code: 'UNAUTHORIZED' });
69
+ if (response.status === 403)
70
+ throw new Core.API.AuthError({ code: 'UNAVAILABLE' });
71
+ throw new Core.API.AuthError({ code: 'UNKNOWN' });
72
+ }
73
+ });
74
+ }
48
75
  /**
49
76
  * Initiates password reset for a customer with the given email.
50
77
  * If such customer exists, they will receive an email from Foxy with further instructions.
@@ -107,6 +134,16 @@ export class API extends Core.API {
107
134
  API.SESSION = 'session';
108
135
  /** Validators for the method arguments in this class (internal). */
109
136
  API.v8n = Object.assign({}, Core.API.v8n, {
137
+ signUpParams: v8n().schema({
138
+ verification: v8n().schema({
139
+ token: v8n().string(),
140
+ type: v8n().passesAnyOf(v8n().exact('hcaptcha')),
141
+ }),
142
+ first_name: v8n().optional(v8n().string().maxLength(50)),
143
+ last_name: v8n().optional(v8n().string().maxLength(50)),
144
+ password: v8n().string().maxLength(50),
145
+ email: v8n().string().maxLength(100),
146
+ }),
110
147
  credentials: v8n().schema({
111
148
  email: v8n().string(),
112
149
  newPassword: v8n().optional(v8n().string()),
@@ -1,4 +1,4 @@
1
- import { getNextTransactionDateConstraints as backendUtility } from '../backend/getNextTransactionDateConstraints';
1
+ import { getNextTransactionDateConstraints as backendUtility } from '../backend/getNextTransactionDateConstraints.js';
2
2
  /**
3
3
  * Finds which next transaction date modification rules are applicable to
4
4
  * the given subscription and merges them together.
@@ -58,6 +58,20 @@ export interface CustomerPortalSettings extends Graph {
58
58
  ssoSecret?: string;
59
59
  /** Life span of session in minutes. Maximum 40320 (4 weeks). */
60
60
  sessionLifespanInMinutes: number;
61
+ /** Self-registration settings. Self-registration is disabled if this field is undefined. */
62
+ signUp?: {
63
+ /** If this field is true, then self-registration is enabled. */
64
+ enabled: boolean;
65
+ /** Client verification settings. */
66
+ verification: {
67
+ /** Verification type. Currently only hCaptcha is supported. */
68
+ type: 'hcaptcha';
69
+ /** hCaptcha site key. If empty, Foxy will use its own hCaptcha site key. */
70
+ siteKey: string;
71
+ /** hCaptcha secret key. If empty, Foxy will use its own hCaptcha secret key. */
72
+ secretKey: string;
73
+ };
74
+ };
61
75
  /** The date this resource was created. */
62
76
  date_created: string | null;
63
77
  /** The date this resource was last modified. */
@@ -4,7 +4,7 @@ declare type AuthErrorParams = {
4
4
  originalError?: unknown;
5
5
  };
6
6
  /** Union of all possible auth error codes. */
7
- declare type UniversalAPIAuthErrorCode = typeof AuthError['NEW_PASSWORD_REQUIRED'] | typeof AuthError['INVALID_NEW_PASSWORD'] | typeof AuthError['UNAUTHORIZED'] | typeof AuthError['UNKNOWN'];
7
+ declare type UniversalAPIAuthErrorCode = typeof AuthError['NEW_PASSWORD_REQUIRED'] | typeof AuthError['INVALID_NEW_PASSWORD'] | typeof AuthError['UNAUTHORIZED'] | typeof AuthError['INVALID_FORM'] | typeof AuthError['UNAVAILABLE'] | typeof AuthError['UNKNOWN'];
8
8
  /**
9
9
  * Base error class for all authentication-related errors in
10
10
  * the APIs that can be used both server and client-side. If you're
@@ -18,6 +18,10 @@ export declare class AuthError extends Error {
18
18
  static readonly INVALID_NEW_PASSWORD = "INVALID_NEW_PASSWORD";
19
19
  /** Credentials are invalid. That could mean empty or invalid email or password or otherwise incorrect auth data. */
20
20
  static readonly UNAUTHORIZED = "UNAUTHORIZED";
21
+ /** Provided form data is invalid, e.g. email is too long or captcha is expired. */
22
+ static readonly INVALID_FORM = "INVALID_FORM";
23
+ /** Provided email is already taken. Applies to customer registration only. */
24
+ static readonly UNAVAILABLE = "UNAVAILABLE";
21
25
  /** Any other or internal error that interrupted authentication. */
22
26
  static readonly UNKNOWN = "UNKNOWN";
23
27
  /** Available class member validators. */
@@ -1,6 +1,6 @@
1
- import * as Core from '../core/index.js';
2
- import type { Credentials } from './types';
1
+ import type { Credentials, SignUpParams } from './types';
3
2
  import type { Graph } from './Graph';
3
+ import * as Core from '../core/index.js';
4
4
  /**
5
5
  * Customer API for adding custom functionality to websites and web apps with our Customer Portal.
6
6
  *
@@ -15,6 +15,7 @@ export declare class API extends Core.API<Graph> {
15
15
  static readonly v8n: {
16
16
  classConstructor: any;
17
17
  } & {
18
+ signUpParams: any;
18
19
  credentials: any;
19
20
  email: any;
20
21
  };
@@ -26,6 +27,15 @@ export declare class API extends Core.API<Graph> {
26
27
  * @param credentials Customer email and password (one-time code).
27
28
  */
28
29
  signIn(credentials: Credentials): Promise<void>;
30
+ /**
31
+ * Creates a new customer account with the given credentials.
32
+ * If the email is already taken, `Core.API.AuthError` with code `UNAVAILABLE` will be thrown.
33
+ * If customer registration is disabled, `Core.API.AuthError` with code `UNAUTHORIZED` will be thrown.
34
+ * If the provided form data is invalid (e.g. captcha is expired), `Core.API.AuthError` with code `INVALID_FORM` will be thrown.
35
+ *
36
+ * @param params Customer information.
37
+ */
38
+ signUp(params: SignUpParams): Promise<void>;
29
39
  /**
30
40
  * Initiates password reset for a customer with the given email.
31
41
  * If such customer exists, they will receive an email from Foxy with further instructions.
@@ -53,6 +53,29 @@ export interface CustomerPortalSettings extends Graph {
53
53
  sso: boolean;
54
54
  /** Life span of session in minutes. Maximum 40320 (4 weeks). */
55
55
  session_lifespan_in_minutes: number;
56
+ /** Determines if a terms of service checkbox is shown on the portal. This value comes from a template config linked to the default template set. */
57
+ tos_checkbox_settings: {
58
+ /** Initial state of the checkbox element. */
59
+ initial_state: 'unchecked' | 'checked';
60
+ /** Hides the checkbox if true. */
61
+ is_hidden: boolean;
62
+ /** Hides the checkbox if "none". Makes accepting ToS mandatory if "required", and optional otherwise. */
63
+ usage: 'none' | 'optional' | 'required';
64
+ /** Public URL of your terms of service agreement. */
65
+ url: string;
66
+ };
67
+ /** Self-registration settings. Self-registration is disabled if this field is undefined. */
68
+ sign_up?: {
69
+ /** Client verification settings. */
70
+ verification: {
71
+ /** hCaptcha site key. If empty, Foxy will use its own hCaptcha site key. */
72
+ site_key: string;
73
+ /** Verification type. Currently only hCaptcha is supported. */
74
+ type: 'hcaptcha';
75
+ };
76
+ /** If this field is true, then self-registration is enabled. */
77
+ enabled: boolean;
78
+ };
56
79
  /** The date this resource was created. */
57
80
  date_created: string | null;
58
81
  /** The date this resource was last modified. */
@@ -6,6 +6,25 @@ export interface Credentials {
6
6
  password: string;
7
7
  }
8
8
 
9
+ /** Account creation parameters. */
10
+ export interface SignUpParams {
11
+ /** Signup verification (currently only hCaptcha is supported). */
12
+ verification: {
13
+ /** Verification type. Currently only hCaptcha is supported. */
14
+ type: 'hcaptcha';
15
+ /** hCaptcha verification token. */
16
+ token: string;
17
+ };
18
+ /** Customer's first name, optional, up to 50 characters. */
19
+ first_name?: string;
20
+ /** Customer's last name, optional, up to 50 characters. */
21
+ last_name?: string;
22
+ /** Customer's password (up to 50 characters). If not provided, Foxy will generate a random password for this account server-side. */
23
+ password?: string;
24
+ /** Customer's email address (up to 100 characters), required. */
25
+ email: string;
26
+ }
27
+
9
28
  export interface Session {
10
29
  session_token: string;
11
30
  expires_in: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@foxy.io/sdk",
3
3
  "type": "commonjs",
4
- "version": "1.10.0",
4
+ "version": "1.11.1",
5
5
  "description": "Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.",
6
6
  "main": "dist/cjs/index.js",
7
7
  "module": "dist/esm/index.js",
@@ -89,6 +89,7 @@
89
89
  "ts-node": "^9.1.1",
90
90
  "ttypescript": "^1.5.15",
91
91
  "typedoc": "^0.22.18",
92
+ "typedoc-plugin-missing-exports": "^1.0.0",
92
93
  "typescript": "^4.0.3",
93
94
  "webpack": "^5.75.0",
94
95
  "webpack-cli": "^4.10.0",