@dyrected/sdk 2.5.12 → 2.5.14
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/dist/index.cjs +57 -15
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +56 -6
- package/package.json +14 -7
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -37,7 +27,43 @@ __export(index_exports, {
|
|
|
37
27
|
generateFreshSetupPrompt: () => generateFreshSetupPrompt
|
|
38
28
|
});
|
|
39
29
|
module.exports = __toCommonJS(index_exports);
|
|
40
|
-
|
|
30
|
+
|
|
31
|
+
// src/utils/stringify.ts
|
|
32
|
+
function stringify(obj, prefix = "") {
|
|
33
|
+
if (obj === null || obj === void 0) {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
const pairs = [];
|
|
37
|
+
for (const key in obj) {
|
|
38
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
39
|
+
const value = obj[key];
|
|
40
|
+
const enKey = prefix ? `${prefix}[${encodeURIComponent(key)}]` : encodeURIComponent(key);
|
|
41
|
+
if (value === null || value === void 0) {
|
|
42
|
+
continue;
|
|
43
|
+
} else if (Array.isArray(value)) {
|
|
44
|
+
for (let i = 0; i < value.length; i++) {
|
|
45
|
+
const val = value[i];
|
|
46
|
+
if (typeof val === "object" && val !== null) {
|
|
47
|
+
pairs.push(stringify(val, `${enKey}[${i}]`));
|
|
48
|
+
} else if (val !== null && val !== void 0) {
|
|
49
|
+
pairs.push(`${enKey}[${i}]=${encodeURIComponent(val)}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else if (typeof value === "object") {
|
|
53
|
+
pairs.push(stringify(value, enKey));
|
|
54
|
+
} else {
|
|
55
|
+
pairs.push(`${enKey}=${encodeURIComponent(value)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return pairs.filter(Boolean).join("&");
|
|
59
|
+
}
|
|
60
|
+
function stringifyQuery(obj, options) {
|
|
61
|
+
const result = stringify(obj);
|
|
62
|
+
if (options?.addQueryPrefix && result) {
|
|
63
|
+
return `?${result}`;
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
41
67
|
|
|
42
68
|
// src/query-builder.ts
|
|
43
69
|
var QueryBuilder = class {
|
|
@@ -953,7 +979,7 @@ var DyrectedClient = class {
|
|
|
953
979
|
if (normalizedArgs.where && typeof normalizedArgs.where === "object") {
|
|
954
980
|
normalizedArgs.where = JSON.stringify(normalizedArgs.where);
|
|
955
981
|
}
|
|
956
|
-
const query =
|
|
982
|
+
const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
|
|
957
983
|
const res = await this.request(`/api/collections/${collection}${query}`);
|
|
958
984
|
if (res.docs.length === 0 && initialData && initialData.length > 0) {
|
|
959
985
|
this.request(`/api/collections/${collection}/seed`, {
|
|
@@ -1031,6 +1057,22 @@ var DyrectedClient = class {
|
|
|
1031
1057
|
acceptInvite: (token, password, extraFields) => this.request(`/api/collections/${slug}/accept-invite`, {
|
|
1032
1058
|
method: "POST",
|
|
1033
1059
|
body: JSON.stringify({ token, password, ...extraFields })
|
|
1060
|
+
}),
|
|
1061
|
+
/**
|
|
1062
|
+
* Change the password for a specific user document.
|
|
1063
|
+
* Non-admins must supply oldPassword. newPassword and confirmPassword must match.
|
|
1064
|
+
*/
|
|
1065
|
+
changePassword: (id, payload) => this.request(`/api/collections/${slug}/${id}/change-password`, {
|
|
1066
|
+
method: "POST",
|
|
1067
|
+
body: JSON.stringify(payload)
|
|
1068
|
+
}),
|
|
1069
|
+
/**
|
|
1070
|
+
* Admin-initiated password reset. Sends a reset link to the given email address.
|
|
1071
|
+
* Wraps the existing POST /forgot-password endpoint.
|
|
1072
|
+
*/
|
|
1073
|
+
sendResetLink: (email) => this.request(`/api/collections/${slug}/forgot-password`, {
|
|
1074
|
+
method: "POST",
|
|
1075
|
+
body: JSON.stringify({ email })
|
|
1034
1076
|
})
|
|
1035
1077
|
};
|
|
1036
1078
|
}
|
|
@@ -1047,7 +1089,7 @@ var DyrectedClient = class {
|
|
|
1047
1089
|
}
|
|
1048
1090
|
async findOne(collection, id, args = {}) {
|
|
1049
1091
|
const { initialData, ...queryArgs } = args;
|
|
1050
|
-
const query =
|
|
1092
|
+
const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
|
|
1051
1093
|
try {
|
|
1052
1094
|
return await this.request(`/api/collections/${collection}/${id}${query}`);
|
|
1053
1095
|
} catch (err) {
|
|
@@ -1083,12 +1125,12 @@ var DyrectedClient = class {
|
|
|
1083
1125
|
async deleteMany(collection, ids) {
|
|
1084
1126
|
return this.request(`/api/collections/${collection}/delete-many`, {
|
|
1085
1127
|
method: "DELETE",
|
|
1086
|
-
body:
|
|
1128
|
+
body: stringify({ ids })
|
|
1087
1129
|
});
|
|
1088
1130
|
}
|
|
1089
1131
|
async getGlobal(slug, args = {}) {
|
|
1090
1132
|
const { initialData, ...queryArgs } = args;
|
|
1091
|
-
const query =
|
|
1133
|
+
const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
|
|
1092
1134
|
try {
|
|
1093
1135
|
const res = await this.request(`/api/globals/${slug}${query}`);
|
|
1094
1136
|
if ((!res || Object.keys(res).length === 0) && initialData) {
|
package/dist/index.d.cts
CHANGED
|
@@ -149,6 +149,26 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
149
149
|
token: string;
|
|
150
150
|
user: TSchema["collections"][K];
|
|
151
151
|
}>;
|
|
152
|
+
/**
|
|
153
|
+
* Change the password for a specific user document.
|
|
154
|
+
* Non-admins must supply oldPassword. newPassword and confirmPassword must match.
|
|
155
|
+
*/
|
|
156
|
+
changePassword: (id: string, payload: {
|
|
157
|
+
oldPassword?: string;
|
|
158
|
+
newPassword: string;
|
|
159
|
+
confirmPassword: string;
|
|
160
|
+
}) => Promise<{
|
|
161
|
+
success: boolean;
|
|
162
|
+
message: string;
|
|
163
|
+
}>;
|
|
164
|
+
/**
|
|
165
|
+
* Admin-initiated password reset. Sends a reset link to the given email address.
|
|
166
|
+
* Wraps the existing POST /forgot-password endpoint.
|
|
167
|
+
*/
|
|
168
|
+
sendResetLink: (email: string) => Promise<{
|
|
169
|
+
success: boolean;
|
|
170
|
+
message: string;
|
|
171
|
+
}>;
|
|
152
172
|
};
|
|
153
173
|
/**
|
|
154
174
|
* Access a global by its slug with a fluent builder.
|
package/dist/index.d.ts
CHANGED
|
@@ -149,6 +149,26 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
|
|
|
149
149
|
token: string;
|
|
150
150
|
user: TSchema["collections"][K];
|
|
151
151
|
}>;
|
|
152
|
+
/**
|
|
153
|
+
* Change the password for a specific user document.
|
|
154
|
+
* Non-admins must supply oldPassword. newPassword and confirmPassword must match.
|
|
155
|
+
*/
|
|
156
|
+
changePassword: (id: string, payload: {
|
|
157
|
+
oldPassword?: string;
|
|
158
|
+
newPassword: string;
|
|
159
|
+
confirmPassword: string;
|
|
160
|
+
}) => Promise<{
|
|
161
|
+
success: boolean;
|
|
162
|
+
message: string;
|
|
163
|
+
}>;
|
|
164
|
+
/**
|
|
165
|
+
* Admin-initiated password reset. Sends a reset link to the given email address.
|
|
166
|
+
* Wraps the existing POST /forgot-password endpoint.
|
|
167
|
+
*/
|
|
168
|
+
sendResetLink: (email: string) => Promise<{
|
|
169
|
+
success: boolean;
|
|
170
|
+
message: string;
|
|
171
|
+
}>;
|
|
152
172
|
};
|
|
153
173
|
/**
|
|
154
174
|
* Access a global by its slug with a fluent builder.
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
1
|
+
// src/utils/stringify.ts
|
|
2
|
+
function stringify(obj, prefix = "") {
|
|
3
|
+
if (obj === null || obj === void 0) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
const pairs = [];
|
|
7
|
+
for (const key in obj) {
|
|
8
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
9
|
+
const value = obj[key];
|
|
10
|
+
const enKey = prefix ? `${prefix}[${encodeURIComponent(key)}]` : encodeURIComponent(key);
|
|
11
|
+
if (value === null || value === void 0) {
|
|
12
|
+
continue;
|
|
13
|
+
} else if (Array.isArray(value)) {
|
|
14
|
+
for (let i = 0; i < value.length; i++) {
|
|
15
|
+
const val = value[i];
|
|
16
|
+
if (typeof val === "object" && val !== null) {
|
|
17
|
+
pairs.push(stringify(val, `${enKey}[${i}]`));
|
|
18
|
+
} else if (val !== null && val !== void 0) {
|
|
19
|
+
pairs.push(`${enKey}[${i}]=${encodeURIComponent(val)}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
} else if (typeof value === "object") {
|
|
23
|
+
pairs.push(stringify(value, enKey));
|
|
24
|
+
} else {
|
|
25
|
+
pairs.push(`${enKey}=${encodeURIComponent(value)}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return pairs.filter(Boolean).join("&");
|
|
29
|
+
}
|
|
30
|
+
function stringifyQuery(obj, options) {
|
|
31
|
+
const result = stringify(obj);
|
|
32
|
+
if (options?.addQueryPrefix && result) {
|
|
33
|
+
return `?${result}`;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
3
37
|
|
|
4
38
|
// src/query-builder.ts
|
|
5
39
|
var QueryBuilder = class {
|
|
@@ -915,7 +949,7 @@ var DyrectedClient = class {
|
|
|
915
949
|
if (normalizedArgs.where && typeof normalizedArgs.where === "object") {
|
|
916
950
|
normalizedArgs.where = JSON.stringify(normalizedArgs.where);
|
|
917
951
|
}
|
|
918
|
-
const query =
|
|
952
|
+
const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
|
|
919
953
|
const res = await this.request(`/api/collections/${collection}${query}`);
|
|
920
954
|
if (res.docs.length === 0 && initialData && initialData.length > 0) {
|
|
921
955
|
this.request(`/api/collections/${collection}/seed`, {
|
|
@@ -993,6 +1027,22 @@ var DyrectedClient = class {
|
|
|
993
1027
|
acceptInvite: (token, password, extraFields) => this.request(`/api/collections/${slug}/accept-invite`, {
|
|
994
1028
|
method: "POST",
|
|
995
1029
|
body: JSON.stringify({ token, password, ...extraFields })
|
|
1030
|
+
}),
|
|
1031
|
+
/**
|
|
1032
|
+
* Change the password for a specific user document.
|
|
1033
|
+
* Non-admins must supply oldPassword. newPassword and confirmPassword must match.
|
|
1034
|
+
*/
|
|
1035
|
+
changePassword: (id, payload) => this.request(`/api/collections/${slug}/${id}/change-password`, {
|
|
1036
|
+
method: "POST",
|
|
1037
|
+
body: JSON.stringify(payload)
|
|
1038
|
+
}),
|
|
1039
|
+
/**
|
|
1040
|
+
* Admin-initiated password reset. Sends a reset link to the given email address.
|
|
1041
|
+
* Wraps the existing POST /forgot-password endpoint.
|
|
1042
|
+
*/
|
|
1043
|
+
sendResetLink: (email) => this.request(`/api/collections/${slug}/forgot-password`, {
|
|
1044
|
+
method: "POST",
|
|
1045
|
+
body: JSON.stringify({ email })
|
|
996
1046
|
})
|
|
997
1047
|
};
|
|
998
1048
|
}
|
|
@@ -1009,7 +1059,7 @@ var DyrectedClient = class {
|
|
|
1009
1059
|
}
|
|
1010
1060
|
async findOne(collection, id, args = {}) {
|
|
1011
1061
|
const { initialData, ...queryArgs } = args;
|
|
1012
|
-
const query =
|
|
1062
|
+
const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
|
|
1013
1063
|
try {
|
|
1014
1064
|
return await this.request(`/api/collections/${collection}/${id}${query}`);
|
|
1015
1065
|
} catch (err) {
|
|
@@ -1045,12 +1095,12 @@ var DyrectedClient = class {
|
|
|
1045
1095
|
async deleteMany(collection, ids) {
|
|
1046
1096
|
return this.request(`/api/collections/${collection}/delete-many`, {
|
|
1047
1097
|
method: "DELETE",
|
|
1048
|
-
body:
|
|
1098
|
+
body: stringify({ ids })
|
|
1049
1099
|
});
|
|
1050
1100
|
}
|
|
1051
1101
|
async getGlobal(slug, args = {}) {
|
|
1052
1102
|
const { initialData, ...queryArgs } = args;
|
|
1053
|
-
const query =
|
|
1103
|
+
const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
|
|
1054
1104
|
try {
|
|
1055
1105
|
const res = await this.request(`/api/globals/${slug}${query}`);
|
|
1056
1106
|
if ((!res || Object.keys(res).length === 0) && initialData) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dyrected/sdk",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -15,15 +15,22 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"tsup": {
|
|
19
|
+
"entry": [
|
|
20
|
+
"src/index.ts"
|
|
21
|
+
],
|
|
22
|
+
"format": [
|
|
23
|
+
"cjs",
|
|
24
|
+
"esm"
|
|
25
|
+
],
|
|
26
|
+
"dts": true
|
|
20
27
|
},
|
|
28
|
+
"dependencies": {},
|
|
21
29
|
"devDependencies": {
|
|
22
|
-
"@types/qs": "^6.15.1",
|
|
23
30
|
"tsup": "^8.5.1",
|
|
24
31
|
"typescript": "^5.4.5",
|
|
25
32
|
"vitest": "^1.0.0",
|
|
26
|
-
"@dyrected/core": "2.5.
|
|
33
|
+
"@dyrected/core": "2.5.14"
|
|
27
34
|
},
|
|
28
35
|
"license": "BSL-1.1",
|
|
29
36
|
"author": "Busola Okeowo <busolaokemoney@gmail.com>",
|
|
@@ -37,8 +44,8 @@
|
|
|
37
44
|
},
|
|
38
45
|
"description": "Client-side SDK for Dyrected CMS",
|
|
39
46
|
"scripts": {
|
|
40
|
-
"build": "tsup
|
|
41
|
-
"dev": "tsup
|
|
47
|
+
"build": "tsup",
|
|
48
|
+
"dev": "tsup --watch",
|
|
42
49
|
"lint": "eslint src",
|
|
43
50
|
"test": "vitest run"
|
|
44
51
|
}
|