@data-loom/auth-js 0.0.2-alpha.2 → 0.0.3

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.
Files changed (137) hide show
  1. package/dist/main/AuthAdminApi.d.ts +4 -0
  2. package/dist/main/AuthAdminApi.d.ts.map +1 -0
  3. package/dist/main/AuthAdminApi.js +9 -0
  4. package/dist/main/AuthAdminApi.js.map +1 -0
  5. package/dist/main/AuthClient.d.ts +4 -0
  6. package/dist/main/AuthClient.d.ts.map +1 -0
  7. package/dist/main/AuthClient.js +9 -0
  8. package/dist/main/AuthClient.js.map +1 -0
  9. package/dist/main/GoTrueAdminApi.d.ts +99 -0
  10. package/dist/main/GoTrueAdminApi.d.ts.map +1 -0
  11. package/dist/main/GoTrueAdminApi.js +268 -0
  12. package/dist/main/GoTrueAdminApi.js.map +1 -0
  13. package/dist/main/GoTrueClient.d.ts +492 -0
  14. package/dist/main/GoTrueClient.d.ts.map +1 -0
  15. package/dist/main/GoTrueClient.js +2227 -0
  16. package/dist/main/GoTrueClient.js.map +1 -0
  17. package/dist/main/index.d.ts +9 -0
  18. package/dist/main/index.d.ts.map +1 -0
  19. package/dist/main/index.js +35 -0
  20. package/dist/main/index.js.map +1 -0
  21. package/dist/main/lib/version.d.ts +2 -0
  22. package/dist/main/lib/version.d.ts.map +1 -0
  23. package/dist/main/lib/version.js +6 -0
  24. package/dist/main/lib/version.js.map +1 -0
  25. package/dist/main/utils/base64url.d.ts +75 -0
  26. package/dist/main/utils/base64url.d.ts.map +1 -0
  27. package/dist/main/utils/base64url.js +270 -0
  28. package/dist/main/utils/base64url.js.map +1 -0
  29. package/dist/main/utils/constants.d.ts +26 -0
  30. package/dist/main/utils/constants.d.ts.map +1 -0
  31. package/dist/main/utils/constants.js +31 -0
  32. package/dist/main/utils/constants.js.map +1 -0
  33. package/dist/main/utils/error-codes.d.ts +7 -0
  34. package/dist/main/utils/error-codes.d.ts.map +1 -0
  35. package/dist/main/utils/error-codes.js +3 -0
  36. package/dist/main/utils/error-codes.js.map +1 -0
  37. package/dist/main/utils/errors.d.ts +100 -0
  38. package/dist/main/utils/errors.d.ts.map +1 -0
  39. package/dist/main/utils/errors.js +137 -0
  40. package/dist/main/utils/errors.js.map +1 -0
  41. package/dist/main/utils/fetch.d.ts +34 -0
  42. package/dist/main/utils/fetch.d.ts.map +1 -0
  43. package/dist/main/utils/fetch.js +195 -0
  44. package/dist/main/utils/fetch.js.map +1 -0
  45. package/dist/main/utils/helpers.d.ts +59 -0
  46. package/dist/main/utils/helpers.d.ts.map +1 -0
  47. package/dist/main/utils/helpers.js +334 -0
  48. package/dist/main/utils/helpers.js.map +1 -0
  49. package/dist/main/utils/local-storage.d.ts +13 -0
  50. package/dist/main/utils/local-storage.d.ts.map +1 -0
  51. package/dist/main/utils/local-storage.js +46 -0
  52. package/dist/main/utils/local-storage.js.map +1 -0
  53. package/dist/main/utils/locks.d.ts +64 -0
  54. package/dist/main/utils/locks.d.ts.map +1 -0
  55. package/dist/main/utils/locks.js +187 -0
  56. package/dist/main/utils/locks.js.map +1 -0
  57. package/dist/main/utils/polyfills.d.ts +5 -0
  58. package/dist/main/utils/polyfills.d.ts.map +1 -0
  59. package/dist/main/utils/polyfills.js +30 -0
  60. package/dist/main/utils/polyfills.js.map +1 -0
  61. package/dist/main/utils/types.d.ts +1074 -0
  62. package/dist/main/utils/types.d.ts.map +1 -0
  63. package/dist/main/utils/types.js +3 -0
  64. package/dist/main/utils/types.js.map +1 -0
  65. package/dist/main/utils/version.d.ts +2 -0
  66. package/dist/main/utils/version.d.ts.map +1 -0
  67. package/dist/main/utils/version.js +6 -0
  68. package/dist/main/utils/version.js.map +1 -0
  69. package/dist/module/AuthAdminApi.d.ts +4 -0
  70. package/dist/module/AuthAdminApi.d.ts.map +1 -0
  71. package/dist/module/AuthAdminApi.js +4 -0
  72. package/dist/module/AuthAdminApi.js.map +1 -0
  73. package/dist/module/AuthClient.d.ts +4 -0
  74. package/dist/module/AuthClient.d.ts.map +1 -0
  75. package/dist/module/AuthClient.js +4 -0
  76. package/dist/module/AuthClient.js.map +1 -0
  77. package/dist/module/GoTrueAdminApi.d.ts +99 -0
  78. package/dist/module/GoTrueAdminApi.d.ts.map +1 -0
  79. package/dist/module/GoTrueAdminApi.js +265 -0
  80. package/dist/module/GoTrueAdminApi.js.map +1 -0
  81. package/dist/module/GoTrueClient.d.ts +492 -0
  82. package/dist/module/GoTrueClient.d.ts.map +1 -0
  83. package/dist/module/GoTrueClient.js +2221 -0
  84. package/dist/module/GoTrueClient.js.map +1 -0
  85. package/dist/module/index.d.ts +9 -0
  86. package/dist/module/index.d.ts.map +1 -0
  87. package/dist/module/index.js +9 -0
  88. package/dist/module/index.js.map +1 -0
  89. package/dist/module/lib/version.d.ts +2 -0
  90. package/dist/module/lib/version.d.ts.map +1 -0
  91. package/dist/module/lib/version.js +3 -0
  92. package/dist/module/lib/version.js.map +1 -0
  93. package/dist/module/utils/base64url.d.ts +75 -0
  94. package/dist/module/utils/base64url.d.ts.map +1 -0
  95. package/dist/module/utils/base64url.js +257 -0
  96. package/dist/module/utils/base64url.js.map +1 -0
  97. package/dist/module/utils/constants.d.ts +26 -0
  98. package/dist/module/utils/constants.d.ts.map +1 -0
  99. package/dist/module/utils/constants.js +28 -0
  100. package/dist/module/utils/constants.js.map +1 -0
  101. package/dist/module/utils/error-codes.d.ts +7 -0
  102. package/dist/module/utils/error-codes.d.ts.map +1 -0
  103. package/dist/module/utils/error-codes.js +2 -0
  104. package/dist/module/utils/error-codes.js.map +1 -0
  105. package/dist/module/utils/errors.d.ts +100 -0
  106. package/dist/module/utils/errors.d.ts.map +1 -0
  107. package/dist/module/utils/errors.js +116 -0
  108. package/dist/module/utils/errors.js.map +1 -0
  109. package/dist/module/utils/fetch.d.ts +34 -0
  110. package/dist/module/utils/fetch.d.ts.map +1 -0
  111. package/dist/module/utils/fetch.js +184 -0
  112. package/dist/module/utils/fetch.js.map +1 -0
  113. package/dist/module/utils/helpers.d.ts +59 -0
  114. package/dist/module/utils/helpers.d.ts.map +1 -0
  115. package/dist/module/utils/helpers.js +288 -0
  116. package/dist/module/utils/helpers.js.map +1 -0
  117. package/dist/module/utils/local-storage.d.ts +13 -0
  118. package/dist/module/utils/local-storage.d.ts.map +1 -0
  119. package/dist/module/utils/local-storage.js +42 -0
  120. package/dist/module/utils/local-storage.js.map +1 -0
  121. package/dist/module/utils/locks.d.ts +64 -0
  122. package/dist/module/utils/locks.d.ts.map +1 -0
  123. package/dist/module/utils/locks.js +179 -0
  124. package/dist/module/utils/locks.js.map +1 -0
  125. package/dist/module/utils/polyfills.d.ts +5 -0
  126. package/dist/module/utils/polyfills.d.ts.map +1 -0
  127. package/dist/module/utils/polyfills.js +26 -0
  128. package/dist/module/utils/polyfills.js.map +1 -0
  129. package/dist/module/utils/types.d.ts +1074 -0
  130. package/dist/module/utils/types.d.ts.map +1 -0
  131. package/dist/module/utils/types.js +2 -0
  132. package/dist/module/utils/types.js.map +1 -0
  133. package/dist/module/utils/version.d.ts +2 -0
  134. package/dist/module/utils/version.d.ts.map +1 -0
  135. package/dist/module/utils/version.js +3 -0
  136. package/dist/module/utils/version.js.map +1 -0
  137. package/package.json +2 -2
@@ -0,0 +1,4 @@
1
+ import GoTrueAdminApi from './GoTrueAdminApi';
2
+ declare const AuthAdminApi: typeof GoTrueAdminApi;
3
+ export default AuthAdminApi;
4
+ //# sourceMappingURL=AuthAdminApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthAdminApi.d.ts","sourceRoot":"","sources":["../../src/AuthAdminApi.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAE7C,QAAA,MAAM,YAAY,uBAAiB,CAAA;AAEnC,eAAe,YAAY,CAAA"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const GoTrueAdminApi_1 = __importDefault(require("./GoTrueAdminApi"));
7
+ const AuthAdminApi = GoTrueAdminApi_1.default;
8
+ exports.default = AuthAdminApi;
9
+ //# sourceMappingURL=AuthAdminApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthAdminApi.js","sourceRoot":"","sources":["../../src/AuthAdminApi.ts"],"names":[],"mappings":";;;;;AAAA,sEAA6C;AAE7C,MAAM,YAAY,GAAG,wBAAc,CAAA;AAEnC,kBAAe,YAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ import GoTrueClient from './GoTrueClient';
2
+ declare const AuthClient: typeof GoTrueClient;
3
+ export default AuthClient;
4
+ //# sourceMappingURL=AuthClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthClient.d.ts","sourceRoot":"","sources":["../../src/AuthClient.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAEzC,QAAA,MAAM,UAAU,qBAAe,CAAA;AAE/B,eAAe,UAAU,CAAA"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const GoTrueClient_1 = __importDefault(require("./GoTrueClient"));
7
+ const AuthClient = GoTrueClient_1.default;
8
+ exports.default = AuthClient;
9
+ //# sourceMappingURL=AuthClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthClient.js","sourceRoot":"","sources":["../../src/AuthClient.ts"],"names":[],"mappings":";;;;;AAAA,kEAAyC;AAEzC,MAAM,UAAU,GAAG,sBAAY,CAAA;AAE/B,kBAAe,UAAU,CAAA"}
@@ -0,0 +1,99 @@
1
+ import { Fetch } from './utils/fetch';
2
+ import { AdminUserAttributes, GenerateLinkParams, GenerateLinkResponse, Pagination, User, UserResponse, GoTrueAdminMFAApi, PageParams } from './utils/types';
3
+ import { AuthError } from './utils/errors';
4
+ export default class GoTrueAdminApi {
5
+ /** Contains all MFA administration methods. */
6
+ mfa: GoTrueAdminMFAApi;
7
+ protected url: string;
8
+ protected headers: {
9
+ [key: string]: string;
10
+ };
11
+ protected fetch: Fetch;
12
+ constructor({ url, headers, fetch, }: {
13
+ url: string;
14
+ headers?: {
15
+ [key: string]: string;
16
+ };
17
+ fetch?: Fetch;
18
+ });
19
+ /**
20
+ * Removes a logged-in session.
21
+ * @param jwt A valid, logged-in JWT.
22
+ * @param scope The logout sope.
23
+ */
24
+ signOut(jwt: string, scope?: 'global' | 'local' | 'others'): Promise<{
25
+ data: null;
26
+ error: AuthError | null;
27
+ }>;
28
+ /**
29
+ * Sends an invite link to an email address.
30
+ * @param email The email address of the user.
31
+ * @param options Additional options to be included when inviting.
32
+ */
33
+ inviteUserByEmail(email: string, options?: {
34
+ /** A custom data object to store additional metadata about the user. This maps to the `auth.users.user_metadata` column. */
35
+ data?: object;
36
+ /** The URL which will be appended to the email link sent to the user's email address. Once clicked the user will end up on this URL. */
37
+ redirectTo?: string;
38
+ }): Promise<UserResponse>;
39
+ /**
40
+ * Generates email links and OTPs to be sent via a custom email provider.
41
+ * @param email The user's email.
42
+ * @param options.password User password. For signup only.
43
+ * @param options.data Optional user metadata. For signup only.
44
+ * @param options.redirectTo The redirect url which should be appended to the generated link
45
+ */
46
+ generateLink(params: GenerateLinkParams): Promise<GenerateLinkResponse>;
47
+ /**
48
+ * Creates a new user.
49
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
50
+ */
51
+ createUser(attributes: AdminUserAttributes): Promise<UserResponse>;
52
+ /**
53
+ * Get a list of users.
54
+ *
55
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
56
+ * @param params An object which supports `page` and `perPage` as numbers, to alter the paginated results.
57
+ */
58
+ listUsers(params?: PageParams): Promise<{
59
+ data: {
60
+ users: User[];
61
+ aud: string;
62
+ } & Pagination;
63
+ error: null;
64
+ } | {
65
+ data: {
66
+ users: [];
67
+ };
68
+ error: AuthError;
69
+ }>;
70
+ /**
71
+ * Get user by id.
72
+ *
73
+ * @param uid The user's unique identifier
74
+ *
75
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
76
+ */
77
+ getUserById(uid: string): Promise<UserResponse>;
78
+ /**
79
+ * Updates the user data.
80
+ *
81
+ * @param attributes The data you want to update.
82
+ *
83
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
84
+ */
85
+ updateUserById(uid: string, attributes: AdminUserAttributes): Promise<UserResponse>;
86
+ /**
87
+ * Delete a user. Requires a `service_role` key.
88
+ *
89
+ * @param id The user id you want to remove.
90
+ * @param shouldSoftDelete If true, then the user will be soft-deleted from the auth schema. Soft deletion allows user identification from the hashed user ID but is not reversible.
91
+ * Defaults to false for backward compatibility.
92
+ *
93
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
94
+ */
95
+ deleteUser(id: string, shouldSoftDelete?: boolean): Promise<UserResponse>;
96
+ private _listFactors;
97
+ private _deleteFactor;
98
+ }
99
+ //# sourceMappingURL=GoTrueAdminApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoTrueAdminApi.d.ts","sourceRoot":"","sources":["../../src/GoTrueAdminApi.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAKN,MAAM,eAAe,CAAA;AAEtB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,iBAAiB,EAKjB,UAAU,EACX,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,SAAS,EAAe,MAAM,gBAAgB,CAAA;AAEvD,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,+CAA+C;IAC/C,GAAG,EAAE,iBAAiB,CAAA;IAEtB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,OAAO,EAAE;QACjB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,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AG,OAAO,CAAC,YAAY,CAAC;IAerD;;;;;;OAMG;IACG,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC;IAgBzF;;;;;;;;OAQG;IACG,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,gBAAgB,UAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;YAkB/D,YAAY;YAyBZ,aAAa;CAsB5B"}
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const fetch_1 = require("./utils/fetch");
15
+ const helpers_1 = require("./utils/helpers");
16
+ const errors_1 = require("./utils/errors");
17
+ class GoTrueAdminApi {
18
+ constructor({ url = '', headers = {}, fetch, }) {
19
+ this.url = url;
20
+ this.headers = headers;
21
+ this.fetch = (0, helpers_1.resolveFetch)(fetch);
22
+ this.mfa = {
23
+ listFactors: this._listFactors.bind(this),
24
+ deleteFactor: this._deleteFactor.bind(this),
25
+ };
26
+ }
27
+ /**
28
+ * Removes a logged-in session.
29
+ * @param jwt A valid, logged-in JWT.
30
+ * @param scope The logout sope.
31
+ */
32
+ async signOut(jwt, scope = 'global') {
33
+ try {
34
+ await (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/logout?scope=${scope}`, {
35
+ headers: this.headers,
36
+ jwt,
37
+ noResolveJson: true,
38
+ });
39
+ return { data: null, error: null };
40
+ }
41
+ catch (error) {
42
+ if ((0, errors_1.isAuthError)(error)) {
43
+ return { data: null, error };
44
+ }
45
+ throw error;
46
+ }
47
+ }
48
+ /**
49
+ * Sends an invite link to an email address.
50
+ * @param email The email address of the user.
51
+ * @param options Additional options to be included when inviting.
52
+ */
53
+ async inviteUserByEmail(email, options = {}) {
54
+ try {
55
+ return await (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/invite`, {
56
+ body: { email, data: options.data },
57
+ headers: this.headers,
58
+ redirectTo: options.redirectTo,
59
+ xform: fetch_1._userResponse,
60
+ });
61
+ }
62
+ catch (error) {
63
+ if ((0, errors_1.isAuthError)(error)) {
64
+ return { data: { user: null }, error };
65
+ }
66
+ throw error;
67
+ }
68
+ }
69
+ /**
70
+ * Generates email links and OTPs to be sent via a custom email provider.
71
+ * @param email The user's email.
72
+ * @param options.password User password. For signup only.
73
+ * @param options.data Optional user metadata. For signup only.
74
+ * @param options.redirectTo The redirect url which should be appended to the generated link
75
+ */
76
+ async generateLink(params) {
77
+ try {
78
+ const { options } = params, rest = __rest(params, ["options"]);
79
+ const body = Object.assign(Object.assign({}, rest), options);
80
+ if ('newEmail' in rest) {
81
+ // replace newEmail with new_email in request body
82
+ body.new_email = rest === null || rest === void 0 ? void 0 : rest.newEmail;
83
+ delete body['newEmail'];
84
+ }
85
+ return await (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/generate_link`, {
86
+ body: body,
87
+ headers: this.headers,
88
+ xform: fetch_1._generateLinkResponse,
89
+ redirectTo: options === null || options === void 0 ? void 0 : options.redirectTo,
90
+ });
91
+ }
92
+ catch (error) {
93
+ if ((0, errors_1.isAuthError)(error)) {
94
+ return {
95
+ data: {
96
+ properties: null,
97
+ user: null,
98
+ },
99
+ error,
100
+ };
101
+ }
102
+ throw error;
103
+ }
104
+ }
105
+ // User Admin API
106
+ /**
107
+ * Creates a new user.
108
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
109
+ */
110
+ async createUser(attributes) {
111
+ try {
112
+ return await (0, fetch_1._request)(this.fetch, 'POST', `${this.url}/admin/users`, {
113
+ body: attributes,
114
+ headers: this.headers,
115
+ xform: fetch_1._userResponse,
116
+ });
117
+ }
118
+ catch (error) {
119
+ if ((0, errors_1.isAuthError)(error)) {
120
+ return { data: { user: null }, error };
121
+ }
122
+ throw error;
123
+ }
124
+ }
125
+ /**
126
+ * Get a list of users.
127
+ *
128
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
129
+ * @param params An object which supports `page` and `perPage` as numbers, to alter the paginated results.
130
+ */
131
+ async listUsers(params) {
132
+ var _a, _b, _c, _d, _e, _f, _g;
133
+ try {
134
+ const pagination = { nextPage: null, lastPage: 0, total: 0 };
135
+ const response = await (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users`, {
136
+ headers: this.headers,
137
+ noResolveJson: true,
138
+ query: {
139
+ page: (_b = (_a = params === null || params === void 0 ? void 0 : params.page) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '',
140
+ per_page: (_d = (_c = params === null || params === void 0 ? void 0 : params.perPage) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : '',
141
+ },
142
+ xform: fetch_1._noResolveJsonResponse,
143
+ });
144
+ if (response.error)
145
+ throw response.error;
146
+ const users = await response.json();
147
+ const total = (_e = response.headers.get('x-total-count')) !== null && _e !== void 0 ? _e : 0;
148
+ const links = (_g = (_f = response.headers.get('link')) === null || _f === void 0 ? void 0 : _f.split(',')) !== null && _g !== void 0 ? _g : [];
149
+ if (links.length > 0) {
150
+ links.forEach((link) => {
151
+ const page = parseInt(link.split(';')[0].split('=')[1].substring(0, 1));
152
+ const rel = JSON.parse(link.split(';')[1].split('=')[1]);
153
+ pagination[`${rel}Page`] = page;
154
+ });
155
+ pagination.total = parseInt(total);
156
+ }
157
+ return { data: Object.assign(Object.assign({}, users), pagination), error: null };
158
+ }
159
+ catch (error) {
160
+ if ((0, errors_1.isAuthError)(error)) {
161
+ return { data: { users: [] }, error };
162
+ }
163
+ throw error;
164
+ }
165
+ }
166
+ /**
167
+ * Get user by id.
168
+ *
169
+ * @param uid The user's unique identifier
170
+ *
171
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
172
+ */
173
+ async getUserById(uid) {
174
+ try {
175
+ return await (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users/${uid}`, {
176
+ headers: this.headers,
177
+ xform: fetch_1._userResponse,
178
+ });
179
+ }
180
+ catch (error) {
181
+ if ((0, errors_1.isAuthError)(error)) {
182
+ return { data: { user: null }, error };
183
+ }
184
+ throw error;
185
+ }
186
+ }
187
+ /**
188
+ * Updates the user data.
189
+ *
190
+ * @param attributes The data you want to update.
191
+ *
192
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
193
+ */
194
+ async updateUserById(uid, attributes) {
195
+ try {
196
+ return await (0, fetch_1._request)(this.fetch, 'PUT', `${this.url}/admin/users/${uid}`, {
197
+ body: attributes,
198
+ headers: this.headers,
199
+ xform: fetch_1._userResponse,
200
+ });
201
+ }
202
+ catch (error) {
203
+ if ((0, errors_1.isAuthError)(error)) {
204
+ return { data: { user: null }, error };
205
+ }
206
+ throw error;
207
+ }
208
+ }
209
+ /**
210
+ * Delete a user. Requires a `service_role` key.
211
+ *
212
+ * @param id The user id you want to remove.
213
+ * @param shouldSoftDelete If true, then the user will be soft-deleted from the auth schema. Soft deletion allows user identification from the hashed user ID but is not reversible.
214
+ * Defaults to false for backward compatibility.
215
+ *
216
+ * This function should only be called on a server. Never expose your `service_role` key in the browser.
217
+ */
218
+ async deleteUser(id, shouldSoftDelete = false) {
219
+ try {
220
+ return await (0, fetch_1._request)(this.fetch, 'DELETE', `${this.url}/admin/users/${id}`, {
221
+ headers: this.headers,
222
+ body: {
223
+ should_soft_delete: shouldSoftDelete,
224
+ },
225
+ xform: fetch_1._userResponse,
226
+ });
227
+ }
228
+ catch (error) {
229
+ if ((0, errors_1.isAuthError)(error)) {
230
+ return { data: { user: null }, error };
231
+ }
232
+ throw error;
233
+ }
234
+ }
235
+ async _listFactors(params) {
236
+ try {
237
+ const { data, error } = await (0, fetch_1._request)(this.fetch, 'GET', `${this.url}/admin/users/${params.userId}/factors`, {
238
+ headers: this.headers,
239
+ xform: (factors) => {
240
+ return { data: { factors }, error: null };
241
+ },
242
+ });
243
+ return { data, error };
244
+ }
245
+ catch (error) {
246
+ if ((0, errors_1.isAuthError)(error)) {
247
+ return { data: null, error };
248
+ }
249
+ throw error;
250
+ }
251
+ }
252
+ async _deleteFactor(params) {
253
+ try {
254
+ const data = await (0, fetch_1._request)(this.fetch, 'DELETE', `${this.url}/admin/users/${params.userId}/factors/${params.id}`, {
255
+ headers: this.headers,
256
+ });
257
+ return { data, error: null };
258
+ }
259
+ catch (error) {
260
+ if ((0, errors_1.isAuthError)(error)) {
261
+ return { data: null, error };
262
+ }
263
+ throw error;
264
+ }
265
+ }
266
+ }
267
+ exports.default = GoTrueAdminApi;
268
+ //# sourceMappingURL=GoTrueAdminApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoTrueAdminApi.js","sourceRoot":"","sources":["../../src/GoTrueAdminApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,yCAMsB;AACtB,6CAA8C;AAe9C,2CAAuD;AAEvD,MAAqB,cAAc;IAUjC,YAAY,EACV,GAAG,GAAG,EAAE,EACR,OAAO,GAAG,EAAE,EACZ,KAAK,GAON;QACC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,KAAK,GAAG,IAAA,sBAAY,EAAC,KAAK,CAAC,CAAA;QAChC,IAAI,CAAC,GAAG,GAAG;YACT,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;YACzC,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;SAC5C,CAAA;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAA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