@tinacms/graphql 0.0.0-ddc5e8e-20250611011547 → 0.0.0-dde3eb3-20251028070343
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/database/util.d.ts +2 -2
- package/dist/index.js +482 -454
- package/dist/index.mjs +483 -455
- package/dist/mdx/index.d.ts +2 -7
- package/dist/resolver/auth-fields.d.ts +31 -0
- package/dist/resolver/error.d.ts +1 -2
- package/dist/resolver/index.d.ts +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -2711,7 +2711,7 @@ var Builder = class {
|
|
|
2711
2711
|
this._buildDataField = async (field) => {
|
|
2712
2712
|
const listWarningMsg = `
|
|
2713
2713
|
WARNING: The user interface for ${field.type} does not support \`list: true\`
|
|
2714
|
-
Visit https://tina.io/docs/
|
|
2714
|
+
Visit https://tina.io/docs/r/content-fields/#list-fields/ for more information
|
|
2715
2715
|
|
|
2716
2716
|
`;
|
|
2717
2717
|
switch (field.type) {
|
|
@@ -3019,7 +3019,7 @@ var validateField = async (field) => {
|
|
|
3019
3019
|
// package.json
|
|
3020
3020
|
var package_default = {
|
|
3021
3021
|
name: "@tinacms/graphql",
|
|
3022
|
-
version: "1.
|
|
3022
|
+
version: "1.6.1",
|
|
3023
3023
|
main: "dist/index.js",
|
|
3024
3024
|
module: "dist/index.mjs",
|
|
3025
3025
|
typings: "dist/index.d.ts",
|
|
@@ -3102,7 +3102,7 @@ var package_default = {
|
|
|
3102
3102
|
typescript: "^5.7.3",
|
|
3103
3103
|
vite: "^4.5.9",
|
|
3104
3104
|
vitest: "^0.32.4",
|
|
3105
|
-
zod: "
|
|
3105
|
+
zod: "catalog:"
|
|
3106
3106
|
}
|
|
3107
3107
|
};
|
|
3108
3108
|
|
|
@@ -3310,249 +3310,10 @@ import { graphql, buildASTSchema, getNamedType, GraphQLError as GraphQLError4 }
|
|
|
3310
3310
|
// src/resolver/index.ts
|
|
3311
3311
|
import path3 from "path";
|
|
3312
3312
|
import isValid from "date-fns/isValid/index.js";
|
|
3313
|
-
|
|
3314
|
-
// src/mdx/index.ts
|
|
3315
|
-
import { parseMDX, stringifyMDX } from "@tinacms/mdx";
|
|
3316
|
-
|
|
3317
|
-
// src/resolver/index.ts
|
|
3318
3313
|
import { JSONPath as JSONPath2 } from "jsonpath-plus";
|
|
3319
3314
|
|
|
3320
|
-
// src/
|
|
3321
|
-
|
|
3322
|
-
constructor(message, extensions) {
|
|
3323
|
-
super(message);
|
|
3324
|
-
if (!this.name) {
|
|
3325
|
-
Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
|
|
3326
|
-
}
|
|
3327
|
-
this.extensions = { ...extensions };
|
|
3328
|
-
}
|
|
3329
|
-
};
|
|
3330
|
-
var TinaFetchError = class extends Error {
|
|
3331
|
-
constructor(message, args) {
|
|
3332
|
-
super(message);
|
|
3333
|
-
this.name = "TinaFetchError";
|
|
3334
|
-
this.collection = args.collection;
|
|
3335
|
-
this.stack = args.stack;
|
|
3336
|
-
this.file = args.file;
|
|
3337
|
-
this.originalError = args.originalError;
|
|
3338
|
-
}
|
|
3339
|
-
};
|
|
3340
|
-
var TinaQueryError = class extends TinaFetchError {
|
|
3341
|
-
constructor(args) {
|
|
3342
|
-
super(
|
|
3343
|
-
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3344
|
-
args
|
|
3345
|
-
);
|
|
3346
|
-
}
|
|
3347
|
-
};
|
|
3348
|
-
var TinaParseDocumentError = class extends TinaFetchError {
|
|
3349
|
-
constructor(args) {
|
|
3350
|
-
super(
|
|
3351
|
-
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3352
|
-
args
|
|
3353
|
-
);
|
|
3354
|
-
}
|
|
3355
|
-
toString() {
|
|
3356
|
-
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
3357
|
-
}
|
|
3358
|
-
};
|
|
3359
|
-
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
3360
|
-
var handleFetchErrorError = (e, verbose) => {
|
|
3361
|
-
if (e instanceof Error) {
|
|
3362
|
-
if (e instanceof TinaFetchError) {
|
|
3363
|
-
if (verbose) {
|
|
3364
|
-
console.log(e.toString());
|
|
3365
|
-
console.log(e);
|
|
3366
|
-
console.log(e.stack);
|
|
3367
|
-
}
|
|
3368
|
-
}
|
|
3369
|
-
} else {
|
|
3370
|
-
console.error(e);
|
|
3371
|
-
}
|
|
3372
|
-
throw e;
|
|
3373
|
-
};
|
|
3374
|
-
|
|
3375
|
-
// src/resolver/filter-utils.ts
|
|
3376
|
-
var resolveReferences = async (filter, fields, resolver) => {
|
|
3377
|
-
for (const fieldKey of Object.keys(filter)) {
|
|
3378
|
-
const fieldDefinition = fields.find(
|
|
3379
|
-
(f) => f.name === fieldKey
|
|
3380
|
-
);
|
|
3381
|
-
if (fieldDefinition) {
|
|
3382
|
-
if (fieldDefinition.type === "reference") {
|
|
3383
|
-
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
3384
|
-
if (edges.length === 1) {
|
|
3385
|
-
filter[fieldKey] = {
|
|
3386
|
-
eq: values[0]
|
|
3387
|
-
};
|
|
3388
|
-
} else if (edges.length > 1) {
|
|
3389
|
-
filter[fieldKey] = {
|
|
3390
|
-
in: values
|
|
3391
|
-
};
|
|
3392
|
-
} else {
|
|
3393
|
-
filter[fieldKey] = {
|
|
3394
|
-
eq: "___null___"
|
|
3395
|
-
};
|
|
3396
|
-
}
|
|
3397
|
-
} else if (fieldDefinition.type === "object") {
|
|
3398
|
-
if (fieldDefinition.templates) {
|
|
3399
|
-
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
3400
|
-
const template = fieldDefinition.templates.find(
|
|
3401
|
-
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
3402
|
-
);
|
|
3403
|
-
if (template) {
|
|
3404
|
-
await resolveReferences(
|
|
3405
|
-
filter[fieldKey][templateName],
|
|
3406
|
-
template.fields,
|
|
3407
|
-
resolver
|
|
3408
|
-
);
|
|
3409
|
-
} else {
|
|
3410
|
-
throw new Error(`Template ${templateName} not found`);
|
|
3411
|
-
}
|
|
3412
|
-
}
|
|
3413
|
-
} else {
|
|
3414
|
-
await resolveReferences(
|
|
3415
|
-
filter[fieldKey],
|
|
3416
|
-
fieldDefinition.fields,
|
|
3417
|
-
resolver
|
|
3418
|
-
);
|
|
3419
|
-
}
|
|
3420
|
-
}
|
|
3421
|
-
} else {
|
|
3422
|
-
throw new Error(`Unable to find field ${fieldKey}`);
|
|
3423
|
-
}
|
|
3424
|
-
}
|
|
3425
|
-
};
|
|
3426
|
-
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
3427
|
-
for (const childFieldName of Object.keys(filterNode)) {
|
|
3428
|
-
const childField = fields.find((field) => field.name === childFieldName);
|
|
3429
|
-
if (!childField) {
|
|
3430
|
-
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
3431
|
-
}
|
|
3432
|
-
collectConditionsForField(
|
|
3433
|
-
childFieldName,
|
|
3434
|
-
childField,
|
|
3435
|
-
filterNode[childFieldName],
|
|
3436
|
-
pathExpression,
|
|
3437
|
-
collectCondition
|
|
3438
|
-
);
|
|
3439
|
-
}
|
|
3440
|
-
};
|
|
3441
|
-
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3442
|
-
if (field.list && field.templates) {
|
|
3443
|
-
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
3444
|
-
const template = field.templates.find(
|
|
3445
|
-
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
3446
|
-
);
|
|
3447
|
-
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
3448
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
3449
|
-
collectConditionsForChildFields(
|
|
3450
|
-
childFilterNode,
|
|
3451
|
-
template.fields,
|
|
3452
|
-
filterPath,
|
|
3453
|
-
collectCondition
|
|
3454
|
-
);
|
|
3455
|
-
}
|
|
3456
|
-
} else {
|
|
3457
|
-
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
3458
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
3459
|
-
collectConditionsForChildFields(
|
|
3460
|
-
filterNode,
|
|
3461
|
-
field.fields,
|
|
3462
|
-
filterPath,
|
|
3463
|
-
collectCondition
|
|
3464
|
-
);
|
|
3465
|
-
}
|
|
3466
|
-
};
|
|
3467
|
-
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3468
|
-
if (field.type === "object") {
|
|
3469
|
-
collectConditionsForObjectField(
|
|
3470
|
-
fieldName,
|
|
3471
|
-
field,
|
|
3472
|
-
filterNode,
|
|
3473
|
-
pathExpression,
|
|
3474
|
-
collectCondition
|
|
3475
|
-
);
|
|
3476
|
-
} else {
|
|
3477
|
-
collectCondition({
|
|
3478
|
-
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
3479
|
-
filterExpression: {
|
|
3480
|
-
_type: field.type,
|
|
3481
|
-
_list: !!field.list,
|
|
3482
|
-
...filterNode
|
|
3483
|
-
}
|
|
3484
|
-
});
|
|
3485
|
-
}
|
|
3486
|
-
};
|
|
3487
|
-
|
|
3488
|
-
// src/resolver/media-utils.ts
|
|
3489
|
-
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3490
|
-
if (config && value) {
|
|
3491
|
-
if (config.useRelativeMedia === true) {
|
|
3492
|
-
return value;
|
|
3493
|
-
}
|
|
3494
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3495
|
-
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
3496
|
-
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
3497
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3498
|
-
schema.config.media.tina.mediaRoot
|
|
3499
|
-
);
|
|
3500
|
-
const strippedURL = value.replace(assetsURL, "");
|
|
3501
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3502
|
-
}
|
|
3503
|
-
if (Array.isArray(value)) {
|
|
3504
|
-
return value.map((v) => {
|
|
3505
|
-
if (!v || typeof v !== "string") return v;
|
|
3506
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3507
|
-
schema.config.media.tina.mediaRoot
|
|
3508
|
-
);
|
|
3509
|
-
const strippedURL = v.replace(assetsURL, "");
|
|
3510
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3511
|
-
});
|
|
3512
|
-
}
|
|
3513
|
-
return value;
|
|
3514
|
-
}
|
|
3515
|
-
return value;
|
|
3516
|
-
} else {
|
|
3517
|
-
return value;
|
|
3518
|
-
}
|
|
3519
|
-
};
|
|
3520
|
-
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3521
|
-
if (config && value) {
|
|
3522
|
-
if (config.useRelativeMedia === true) {
|
|
3523
|
-
return value;
|
|
3524
|
-
}
|
|
3525
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3526
|
-
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
3527
|
-
if (typeof value === "string") {
|
|
3528
|
-
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
3529
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3530
|
-
}
|
|
3531
|
-
if (Array.isArray(value)) {
|
|
3532
|
-
return value.map((v) => {
|
|
3533
|
-
if (!v || typeof v !== "string") return v;
|
|
3534
|
-
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3535
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3536
|
-
});
|
|
3537
|
-
}
|
|
3538
|
-
}
|
|
3539
|
-
return value;
|
|
3540
|
-
} else {
|
|
3541
|
-
return value;
|
|
3542
|
-
}
|
|
3543
|
-
};
|
|
3544
|
-
var cleanUpSlashes = (path7) => {
|
|
3545
|
-
if (path7) {
|
|
3546
|
-
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
3547
|
-
}
|
|
3548
|
-
return "";
|
|
3549
|
-
};
|
|
3550
|
-
var hasTinaMediaConfig = (schema) => {
|
|
3551
|
-
if (!schema.config?.media?.tina) return false;
|
|
3552
|
-
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
3553
|
-
return false;
|
|
3554
|
-
return true;
|
|
3555
|
-
};
|
|
3315
|
+
// src/mdx/index.ts
|
|
3316
|
+
import { parseMDX, serializeMDX } from "@tinacms/mdx";
|
|
3556
3317
|
|
|
3557
3318
|
// src/resolver/index.ts
|
|
3558
3319
|
import { GraphQLError as GraphQLError2 } from "graphql";
|
|
@@ -3615,13 +3376,13 @@ import path2 from "path";
|
|
|
3615
3376
|
|
|
3616
3377
|
// src/database/util.ts
|
|
3617
3378
|
import toml from "@iarna/toml";
|
|
3618
|
-
import yaml from "js-yaml";
|
|
3619
|
-
import matter from "gray-matter";
|
|
3620
3379
|
import {
|
|
3621
3380
|
normalizePath
|
|
3622
3381
|
} from "@tinacms/schema-tools";
|
|
3623
|
-
import
|
|
3382
|
+
import matter from "gray-matter";
|
|
3383
|
+
import yaml from "js-yaml";
|
|
3624
3384
|
import path from "path";
|
|
3385
|
+
import micromatch from "micromatch";
|
|
3625
3386
|
|
|
3626
3387
|
// src/database/alias-utils.ts
|
|
3627
3388
|
var replaceBlockAliases = (template, item) => {
|
|
@@ -4508,106 +4269,342 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
|
|
|
4508
4269
|
});
|
|
4509
4270
|
}
|
|
4510
4271
|
}
|
|
4511
|
-
return result;
|
|
4272
|
+
return result;
|
|
4273
|
+
};
|
|
4274
|
+
var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opType, level, escapeStr = stringEscaper) => {
|
|
4275
|
+
const result = [];
|
|
4276
|
+
if (collection) {
|
|
4277
|
+
const collectionSublevel = level.sublevel(collection, SUBLEVEL_OPTIONS);
|
|
4278
|
+
for (const [sort, definition] of Object.entries(indexDefinitions)) {
|
|
4279
|
+
const indexedValue = makeKeyForField(definition, data, escapeStr);
|
|
4280
|
+
const indexSublevel = collectionSublevel.sublevel(sort, SUBLEVEL_OPTIONS);
|
|
4281
|
+
if (sort === DEFAULT_COLLECTION_SORT_KEY) {
|
|
4282
|
+
result.push({
|
|
4283
|
+
type: opType,
|
|
4284
|
+
key: filepath,
|
|
4285
|
+
sublevel: indexSublevel,
|
|
4286
|
+
value: opType === "put" ? {} : void 0
|
|
4287
|
+
});
|
|
4288
|
+
} else {
|
|
4289
|
+
if (indexedValue) {
|
|
4290
|
+
result.push({
|
|
4291
|
+
type: opType,
|
|
4292
|
+
key: `${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
|
|
4293
|
+
sublevel: indexSublevel,
|
|
4294
|
+
value: opType === "put" ? {} : void 0
|
|
4295
|
+
});
|
|
4296
|
+
}
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4299
|
+
}
|
|
4300
|
+
return result;
|
|
4301
|
+
};
|
|
4302
|
+
var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
|
|
4303
|
+
const result = [];
|
|
4304
|
+
if (collection) {
|
|
4305
|
+
for (const [c, referencePaths] of Object.entries(references || {})) {
|
|
4306
|
+
if (!referencePaths.length) {
|
|
4307
|
+
continue;
|
|
4308
|
+
}
|
|
4309
|
+
const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
|
|
4310
|
+
const refSublevel = collectionSublevel.sublevel(
|
|
4311
|
+
REFS_COLLECTIONS_SORT_KEY,
|
|
4312
|
+
SUBLEVEL_OPTIONS
|
|
4313
|
+
);
|
|
4314
|
+
const references2 = {};
|
|
4315
|
+
for (const path7 of referencePaths) {
|
|
4316
|
+
const ref = JSONPath({ path: path7, json: data });
|
|
4317
|
+
if (!ref) {
|
|
4318
|
+
continue;
|
|
4319
|
+
}
|
|
4320
|
+
if (Array.isArray(ref)) {
|
|
4321
|
+
for (const r of ref) {
|
|
4322
|
+
if (!r) {
|
|
4323
|
+
continue;
|
|
4324
|
+
}
|
|
4325
|
+
if (references2[r]) {
|
|
4326
|
+
references2[r].push(path7);
|
|
4327
|
+
} else {
|
|
4328
|
+
references2[r] = [path7];
|
|
4329
|
+
}
|
|
4330
|
+
}
|
|
4331
|
+
} else {
|
|
4332
|
+
if (references2[ref]) {
|
|
4333
|
+
references2[ref].push(path7);
|
|
4334
|
+
} else {
|
|
4335
|
+
references2[ref] = [path7];
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4339
|
+
for (const ref of Object.keys(references2)) {
|
|
4340
|
+
for (const path7 of references2[ref]) {
|
|
4341
|
+
result.push({
|
|
4342
|
+
type: opType,
|
|
4343
|
+
key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
|
|
4344
|
+
sublevel: refSublevel,
|
|
4345
|
+
value: opType === "put" ? {} : void 0
|
|
4346
|
+
});
|
|
4347
|
+
}
|
|
4348
|
+
}
|
|
4349
|
+
}
|
|
4350
|
+
}
|
|
4351
|
+
return result;
|
|
4352
|
+
};
|
|
4353
|
+
var makeStringEscaper = (regex, replacement) => {
|
|
4354
|
+
return (input) => {
|
|
4355
|
+
if (Array.isArray(input)) {
|
|
4356
|
+
return input.map(
|
|
4357
|
+
(val) => val.replace(regex, replacement)
|
|
4358
|
+
);
|
|
4359
|
+
} else {
|
|
4360
|
+
if (typeof input === "string") {
|
|
4361
|
+
return input.replace(regex, replacement);
|
|
4362
|
+
} else {
|
|
4363
|
+
return input;
|
|
4364
|
+
}
|
|
4365
|
+
}
|
|
4366
|
+
};
|
|
4367
|
+
};
|
|
4368
|
+
var stringEscaper = makeStringEscaper(
|
|
4369
|
+
new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"),
|
|
4370
|
+
encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
|
|
4371
|
+
);
|
|
4372
|
+
|
|
4373
|
+
// src/resolver/error.ts
|
|
4374
|
+
var TinaGraphQLError = class extends Error {
|
|
4375
|
+
constructor(message, extensions) {
|
|
4376
|
+
super(message);
|
|
4377
|
+
if (!this.name) {
|
|
4378
|
+
Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
|
|
4379
|
+
}
|
|
4380
|
+
this.extensions = { ...extensions };
|
|
4381
|
+
}
|
|
4382
|
+
};
|
|
4383
|
+
var TinaFetchError = class extends Error {
|
|
4384
|
+
constructor(message, args) {
|
|
4385
|
+
super(message);
|
|
4386
|
+
this.name = "TinaFetchError";
|
|
4387
|
+
this.collection = args.collection;
|
|
4388
|
+
this.file = args.file;
|
|
4389
|
+
this.originalError = args.originalError;
|
|
4390
|
+
}
|
|
4391
|
+
};
|
|
4392
|
+
var TinaQueryError = class extends TinaFetchError {
|
|
4393
|
+
constructor(args) {
|
|
4394
|
+
super(
|
|
4395
|
+
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4396
|
+
args
|
|
4397
|
+
);
|
|
4398
|
+
}
|
|
4399
|
+
};
|
|
4400
|
+
var TinaParseDocumentError = class extends TinaFetchError {
|
|
4401
|
+
constructor(args) {
|
|
4402
|
+
super(
|
|
4403
|
+
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4404
|
+
args
|
|
4405
|
+
);
|
|
4406
|
+
}
|
|
4407
|
+
toString() {
|
|
4408
|
+
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
4409
|
+
}
|
|
4410
|
+
};
|
|
4411
|
+
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
4412
|
+
var handleFetchErrorError = (e, verbose) => {
|
|
4413
|
+
if (e instanceof Error) {
|
|
4414
|
+
if (e instanceof TinaFetchError) {
|
|
4415
|
+
if (verbose) {
|
|
4416
|
+
console.log(e.toString());
|
|
4417
|
+
console.log(e);
|
|
4418
|
+
console.log(e.stack);
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
} else {
|
|
4422
|
+
console.error(e);
|
|
4423
|
+
}
|
|
4424
|
+
throw e;
|
|
4425
|
+
};
|
|
4426
|
+
|
|
4427
|
+
// src/resolver/filter-utils.ts
|
|
4428
|
+
var resolveReferences = async (filter, fields, resolver) => {
|
|
4429
|
+
for (const fieldKey of Object.keys(filter)) {
|
|
4430
|
+
const fieldDefinition = fields.find(
|
|
4431
|
+
(f) => f.name === fieldKey
|
|
4432
|
+
);
|
|
4433
|
+
if (fieldDefinition) {
|
|
4434
|
+
if (fieldDefinition.type === "reference") {
|
|
4435
|
+
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
4436
|
+
if (edges.length === 1) {
|
|
4437
|
+
filter[fieldKey] = {
|
|
4438
|
+
eq: values[0]
|
|
4439
|
+
};
|
|
4440
|
+
} else if (edges.length > 1) {
|
|
4441
|
+
filter[fieldKey] = {
|
|
4442
|
+
in: values
|
|
4443
|
+
};
|
|
4444
|
+
} else {
|
|
4445
|
+
filter[fieldKey] = {
|
|
4446
|
+
eq: "___null___"
|
|
4447
|
+
};
|
|
4448
|
+
}
|
|
4449
|
+
} else if (fieldDefinition.type === "object") {
|
|
4450
|
+
if (fieldDefinition.templates) {
|
|
4451
|
+
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
4452
|
+
const template = fieldDefinition.templates.find(
|
|
4453
|
+
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
4454
|
+
);
|
|
4455
|
+
if (template) {
|
|
4456
|
+
await resolveReferences(
|
|
4457
|
+
filter[fieldKey][templateName],
|
|
4458
|
+
template.fields,
|
|
4459
|
+
resolver
|
|
4460
|
+
);
|
|
4461
|
+
} else {
|
|
4462
|
+
throw new Error(`Template ${templateName} not found`);
|
|
4463
|
+
}
|
|
4464
|
+
}
|
|
4465
|
+
} else {
|
|
4466
|
+
await resolveReferences(
|
|
4467
|
+
filter[fieldKey],
|
|
4468
|
+
fieldDefinition.fields,
|
|
4469
|
+
resolver
|
|
4470
|
+
);
|
|
4471
|
+
}
|
|
4472
|
+
}
|
|
4473
|
+
} else {
|
|
4474
|
+
throw new Error(`Unable to find field ${fieldKey}`);
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4477
|
+
};
|
|
4478
|
+
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
4479
|
+
for (const childFieldName of Object.keys(filterNode)) {
|
|
4480
|
+
const childField = fields.find((field) => field.name === childFieldName);
|
|
4481
|
+
if (!childField) {
|
|
4482
|
+
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
4483
|
+
}
|
|
4484
|
+
collectConditionsForField(
|
|
4485
|
+
childFieldName,
|
|
4486
|
+
childField,
|
|
4487
|
+
filterNode[childFieldName],
|
|
4488
|
+
pathExpression,
|
|
4489
|
+
collectCondition
|
|
4490
|
+
);
|
|
4491
|
+
}
|
|
4492
|
+
};
|
|
4493
|
+
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4494
|
+
if (field.list && field.templates) {
|
|
4495
|
+
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
4496
|
+
const template = field.templates.find(
|
|
4497
|
+
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
4498
|
+
);
|
|
4499
|
+
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
4500
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
4501
|
+
collectConditionsForChildFields(
|
|
4502
|
+
childFilterNode,
|
|
4503
|
+
template.fields,
|
|
4504
|
+
filterPath,
|
|
4505
|
+
collectCondition
|
|
4506
|
+
);
|
|
4507
|
+
}
|
|
4508
|
+
} else {
|
|
4509
|
+
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
4510
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
4511
|
+
collectConditionsForChildFields(
|
|
4512
|
+
filterNode,
|
|
4513
|
+
field.fields,
|
|
4514
|
+
filterPath,
|
|
4515
|
+
collectCondition
|
|
4516
|
+
);
|
|
4517
|
+
}
|
|
4512
4518
|
};
|
|
4513
|
-
var
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
result.push({
|
|
4530
|
-
type: opType,
|
|
4531
|
-
key: `${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
|
|
4532
|
-
sublevel: indexSublevel,
|
|
4533
|
-
value: opType === "put" ? {} : void 0
|
|
4534
|
-
});
|
|
4535
|
-
}
|
|
4519
|
+
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4520
|
+
if (field.type === "object") {
|
|
4521
|
+
collectConditionsForObjectField(
|
|
4522
|
+
fieldName,
|
|
4523
|
+
field,
|
|
4524
|
+
filterNode,
|
|
4525
|
+
pathExpression,
|
|
4526
|
+
collectCondition
|
|
4527
|
+
);
|
|
4528
|
+
} else {
|
|
4529
|
+
collectCondition({
|
|
4530
|
+
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
4531
|
+
filterExpression: {
|
|
4532
|
+
_type: field.type,
|
|
4533
|
+
_list: !!field.list,
|
|
4534
|
+
...filterNode
|
|
4536
4535
|
}
|
|
4537
|
-
}
|
|
4536
|
+
});
|
|
4538
4537
|
}
|
|
4539
|
-
return result;
|
|
4540
4538
|
};
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
const
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
if (!ref) {
|
|
4557
|
-
continue;
|
|
4558
|
-
}
|
|
4559
|
-
if (Array.isArray(ref)) {
|
|
4560
|
-
for (const r of ref) {
|
|
4561
|
-
if (!r) {
|
|
4562
|
-
continue;
|
|
4563
|
-
}
|
|
4564
|
-
if (references2[r]) {
|
|
4565
|
-
references2[r].push(path7);
|
|
4566
|
-
} else {
|
|
4567
|
-
references2[r] = [path7];
|
|
4568
|
-
}
|
|
4569
|
-
}
|
|
4570
|
-
} else {
|
|
4571
|
-
if (references2[ref]) {
|
|
4572
|
-
references2[ref].push(path7);
|
|
4573
|
-
} else {
|
|
4574
|
-
references2[ref] = [path7];
|
|
4575
|
-
}
|
|
4576
|
-
}
|
|
4539
|
+
|
|
4540
|
+
// src/resolver/media-utils.ts
|
|
4541
|
+
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4542
|
+
if (config && value) {
|
|
4543
|
+
if (config.useRelativeMedia === true) {
|
|
4544
|
+
return value;
|
|
4545
|
+
}
|
|
4546
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4547
|
+
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
4548
|
+
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
4549
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4550
|
+
schema.config.media.tina.mediaRoot
|
|
4551
|
+
);
|
|
4552
|
+
const strippedURL = value.replace(assetsURL, "");
|
|
4553
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4577
4554
|
}
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
}
|
|
4586
|
-
}
|
|
4555
|
+
if (Array.isArray(value)) {
|
|
4556
|
+
return value.map((v) => {
|
|
4557
|
+
if (!v || typeof v !== "string") return v;
|
|
4558
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4559
|
+
schema.config.media.tina.mediaRoot
|
|
4560
|
+
);
|
|
4561
|
+
const strippedURL = v.replace(assetsURL, "");
|
|
4562
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4563
|
+
});
|
|
4587
4564
|
}
|
|
4565
|
+
return value;
|
|
4588
4566
|
}
|
|
4567
|
+
return value;
|
|
4568
|
+
} else {
|
|
4569
|
+
return value;
|
|
4589
4570
|
}
|
|
4590
|
-
return result;
|
|
4591
4571
|
};
|
|
4592
|
-
var
|
|
4593
|
-
|
|
4594
|
-
if (
|
|
4595
|
-
return
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
if (typeof
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4572
|
+
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4573
|
+
if (config && value) {
|
|
4574
|
+
if (config.useRelativeMedia === true) {
|
|
4575
|
+
return value;
|
|
4576
|
+
}
|
|
4577
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4578
|
+
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
4579
|
+
if (typeof value === "string") {
|
|
4580
|
+
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
4581
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4582
|
+
}
|
|
4583
|
+
if (Array.isArray(value)) {
|
|
4584
|
+
return value.map((v) => {
|
|
4585
|
+
if (!v || typeof v !== "string") return v;
|
|
4586
|
+
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
4587
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4588
|
+
});
|
|
4603
4589
|
}
|
|
4604
4590
|
}
|
|
4605
|
-
|
|
4591
|
+
return value;
|
|
4592
|
+
} else {
|
|
4593
|
+
return value;
|
|
4594
|
+
}
|
|
4595
|
+
};
|
|
4596
|
+
var cleanUpSlashes = (path7) => {
|
|
4597
|
+
if (path7) {
|
|
4598
|
+
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
4599
|
+
}
|
|
4600
|
+
return "";
|
|
4601
|
+
};
|
|
4602
|
+
var hasTinaMediaConfig = (schema) => {
|
|
4603
|
+
if (!schema.config?.media?.tina) return false;
|
|
4604
|
+
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
4605
|
+
return false;
|
|
4606
|
+
return true;
|
|
4606
4607
|
};
|
|
4607
|
-
var stringEscaper = makeStringEscaper(
|
|
4608
|
-
new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"),
|
|
4609
|
-
encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
|
|
4610
|
-
);
|
|
4611
4608
|
|
|
4612
4609
|
// src/resolver/index.ts
|
|
4613
4610
|
var createResolver = (args) => {
|
|
@@ -4769,8 +4766,7 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4769
4766
|
originalError: e,
|
|
4770
4767
|
collection: collection.name,
|
|
4771
4768
|
includeAuditMessage: !isAudit,
|
|
4772
|
-
file: relativePath
|
|
4773
|
-
stack: e.stack
|
|
4769
|
+
file: relativePath
|
|
4774
4770
|
});
|
|
4775
4771
|
}
|
|
4776
4772
|
const titleField = template.fields.find((x) => {
|
|
@@ -5574,7 +5570,7 @@ var Resolver = class {
|
|
|
5574
5570
|
}
|
|
5575
5571
|
break;
|
|
5576
5572
|
case "rich-text":
|
|
5577
|
-
accum[fieldName] =
|
|
5573
|
+
accum[fieldName] = serializeMDX(
|
|
5578
5574
|
fieldValue,
|
|
5579
5575
|
field,
|
|
5580
5576
|
(fieldValue2) => resolveMediaCloudToRelative(
|
|
@@ -5681,8 +5677,129 @@ var resolveDateInput = (value) => {
|
|
|
5681
5677
|
return date;
|
|
5682
5678
|
};
|
|
5683
5679
|
|
|
5684
|
-
// src/
|
|
5680
|
+
// src/resolver/auth-fields.ts
|
|
5685
5681
|
import set from "lodash.set";
|
|
5682
|
+
async function getUserDocumentContext(tinaSchema, resolver) {
|
|
5683
|
+
const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
|
|
5684
|
+
if (!collection) {
|
|
5685
|
+
throw new Error("Auth collection not found");
|
|
5686
|
+
}
|
|
5687
|
+
const userFields = mapUserFields(collection, ["_rawData"]);
|
|
5688
|
+
if (!userFields.length) {
|
|
5689
|
+
throw new Error(`No user field found in collection ${collection.name}`);
|
|
5690
|
+
}
|
|
5691
|
+
if (userFields.length > 1) {
|
|
5692
|
+
throw new Error(
|
|
5693
|
+
`Multiple user fields found in collection ${collection.name}`
|
|
5694
|
+
);
|
|
5695
|
+
}
|
|
5696
|
+
const userField = userFields[0];
|
|
5697
|
+
const realPath = `${collection.path}/index.json`;
|
|
5698
|
+
const userDoc = await resolver.getDocument(realPath);
|
|
5699
|
+
const users = get(userDoc, userField.path);
|
|
5700
|
+
if (!users) {
|
|
5701
|
+
throw new Error("No users found");
|
|
5702
|
+
}
|
|
5703
|
+
return { collection, userField, users, userDoc, realPath };
|
|
5704
|
+
}
|
|
5705
|
+
function findUserInCollection(users, userField, userSub) {
|
|
5706
|
+
const { idFieldName } = userField;
|
|
5707
|
+
if (!idFieldName) {
|
|
5708
|
+
throw new Error("No uid field found on user field");
|
|
5709
|
+
}
|
|
5710
|
+
return users.find((u) => u[idFieldName] === userSub) || null;
|
|
5711
|
+
}
|
|
5712
|
+
async function handleAuthenticate({
|
|
5713
|
+
tinaSchema,
|
|
5714
|
+
resolver,
|
|
5715
|
+
sub,
|
|
5716
|
+
password,
|
|
5717
|
+
ctxUser
|
|
5718
|
+
}) {
|
|
5719
|
+
const userSub = sub || ctxUser?.sub;
|
|
5720
|
+
const { userField, users } = await getUserDocumentContext(
|
|
5721
|
+
tinaSchema,
|
|
5722
|
+
resolver
|
|
5723
|
+
);
|
|
5724
|
+
const user = findUserInCollection(users, userField, userSub);
|
|
5725
|
+
if (!user) {
|
|
5726
|
+
return null;
|
|
5727
|
+
}
|
|
5728
|
+
const { passwordFieldName } = userField;
|
|
5729
|
+
const saltedHash = get(user, [passwordFieldName || "", "value"]);
|
|
5730
|
+
if (!saltedHash) {
|
|
5731
|
+
throw new Error("No password field found on user field");
|
|
5732
|
+
}
|
|
5733
|
+
const matches = await checkPasswordHash({
|
|
5734
|
+
saltedHash,
|
|
5735
|
+
password
|
|
5736
|
+
});
|
|
5737
|
+
return matches ? user : null;
|
|
5738
|
+
}
|
|
5739
|
+
async function handleAuthorize({
|
|
5740
|
+
tinaSchema,
|
|
5741
|
+
resolver,
|
|
5742
|
+
sub,
|
|
5743
|
+
ctxUser
|
|
5744
|
+
}) {
|
|
5745
|
+
const userSub = sub || ctxUser?.sub;
|
|
5746
|
+
const { userField, users } = await getUserDocumentContext(
|
|
5747
|
+
tinaSchema,
|
|
5748
|
+
resolver
|
|
5749
|
+
);
|
|
5750
|
+
const user = findUserInCollection(users, userField, userSub);
|
|
5751
|
+
return user ? user : null;
|
|
5752
|
+
}
|
|
5753
|
+
async function handleUpdatePassword({
|
|
5754
|
+
tinaSchema,
|
|
5755
|
+
resolver,
|
|
5756
|
+
password,
|
|
5757
|
+
ctxUser
|
|
5758
|
+
}) {
|
|
5759
|
+
if (!ctxUser?.sub) {
|
|
5760
|
+
throw new Error("Not authorized");
|
|
5761
|
+
}
|
|
5762
|
+
if (!password) {
|
|
5763
|
+
throw new Error("No password provided");
|
|
5764
|
+
}
|
|
5765
|
+
const { collection, userField, users, realPath } = await getUserDocumentContext(tinaSchema, resolver);
|
|
5766
|
+
const { idFieldName, passwordFieldName } = userField;
|
|
5767
|
+
const user = users.find((u) => u[idFieldName] === ctxUser.sub);
|
|
5768
|
+
if (!user) {
|
|
5769
|
+
throw new Error("Not authorized");
|
|
5770
|
+
}
|
|
5771
|
+
user[passwordFieldName] = {
|
|
5772
|
+
value: password,
|
|
5773
|
+
passwordChangeRequired: false
|
|
5774
|
+
};
|
|
5775
|
+
const params = {};
|
|
5776
|
+
set(
|
|
5777
|
+
params,
|
|
5778
|
+
userField.path.slice(1),
|
|
5779
|
+
// remove _rawData from users path
|
|
5780
|
+
users.map((u) => {
|
|
5781
|
+
if (user[idFieldName] === u[idFieldName]) {
|
|
5782
|
+
return user;
|
|
5783
|
+
}
|
|
5784
|
+
return {
|
|
5785
|
+
// don't overwrite other users' passwords
|
|
5786
|
+
...u,
|
|
5787
|
+
[passwordFieldName]: {
|
|
5788
|
+
...u[passwordFieldName],
|
|
5789
|
+
value: ""
|
|
5790
|
+
}
|
|
5791
|
+
};
|
|
5792
|
+
})
|
|
5793
|
+
);
|
|
5794
|
+
await resolver.updateResolveDocument({
|
|
5795
|
+
collection,
|
|
5796
|
+
args: { params },
|
|
5797
|
+
realPath,
|
|
5798
|
+
isCollectionSpecific: true,
|
|
5799
|
+
isAddPendingDocument: false
|
|
5800
|
+
});
|
|
5801
|
+
return true;
|
|
5802
|
+
}
|
|
5686
5803
|
|
|
5687
5804
|
// src/error.ts
|
|
5688
5805
|
import { GraphQLError as GraphQLError3 } from "graphql";
|
|
@@ -5792,119 +5909,33 @@ var resolve = async ({
|
|
|
5792
5909
|
);
|
|
5793
5910
|
}
|
|
5794
5911
|
}
|
|
5795
|
-
if (info.fieldName === "authenticate"
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
const realPath = `${collection.path}/index.json`;
|
|
5814
|
-
const userDoc = await resolver.getDocument(realPath);
|
|
5815
|
-
const users = get(userDoc, userField.path);
|
|
5816
|
-
if (!users) {
|
|
5817
|
-
throw new Error("No users found");
|
|
5818
|
-
}
|
|
5819
|
-
const { idFieldName, passwordFieldName } = userField;
|
|
5820
|
-
if (!idFieldName) {
|
|
5821
|
-
throw new Error("No uid field found on user field");
|
|
5822
|
-
}
|
|
5823
|
-
const user = users.find((u) => u[idFieldName] === sub);
|
|
5824
|
-
if (!user) {
|
|
5825
|
-
return null;
|
|
5826
|
-
}
|
|
5827
|
-
if (info.fieldName === "authenticate") {
|
|
5828
|
-
const saltedHash = get(user, [passwordFieldName || "", "value"]);
|
|
5829
|
-
if (!saltedHash) {
|
|
5830
|
-
throw new Error("No password field found on user field");
|
|
5831
|
-
}
|
|
5832
|
-
const matches = await checkPasswordHash({
|
|
5833
|
-
saltedHash,
|
|
5834
|
-
password: args.password
|
|
5835
|
-
});
|
|
5836
|
-
if (matches) {
|
|
5837
|
-
return user;
|
|
5838
|
-
}
|
|
5839
|
-
return null;
|
|
5840
|
-
}
|
|
5841
|
-
return user;
|
|
5912
|
+
if (info.fieldName === "authenticate") {
|
|
5913
|
+
return handleAuthenticate({
|
|
5914
|
+
tinaSchema,
|
|
5915
|
+
resolver,
|
|
5916
|
+
sub: args.sub,
|
|
5917
|
+
password: args.password,
|
|
5918
|
+
info,
|
|
5919
|
+
ctxUser
|
|
5920
|
+
});
|
|
5921
|
+
}
|
|
5922
|
+
if (info.fieldName === "authorize") {
|
|
5923
|
+
return handleAuthorize({
|
|
5924
|
+
tinaSchema,
|
|
5925
|
+
resolver,
|
|
5926
|
+
sub: args.sub,
|
|
5927
|
+
info,
|
|
5928
|
+
ctxUser
|
|
5929
|
+
});
|
|
5842
5930
|
}
|
|
5843
5931
|
if (info.fieldName === "updatePassword") {
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
|
|
5851
|
-
if (!collection) {
|
|
5852
|
-
throw new Error("Auth collection not found");
|
|
5853
|
-
}
|
|
5854
|
-
const userFields = mapUserFields(collection, ["_rawData"]);
|
|
5855
|
-
if (!userFields.length) {
|
|
5856
|
-
throw new Error(
|
|
5857
|
-
`No user field found in collection ${collection.name}`
|
|
5858
|
-
);
|
|
5859
|
-
}
|
|
5860
|
-
if (userFields.length > 1) {
|
|
5861
|
-
throw new Error(
|
|
5862
|
-
`Multiple user fields found in collection ${collection.name}`
|
|
5863
|
-
);
|
|
5864
|
-
}
|
|
5865
|
-
const userField = userFields[0];
|
|
5866
|
-
const realPath = `${collection.path}/index.json`;
|
|
5867
|
-
const userDoc = await resolver.getDocument(realPath);
|
|
5868
|
-
const users = get(userDoc, userField.path);
|
|
5869
|
-
if (!users) {
|
|
5870
|
-
throw new Error("No users found");
|
|
5871
|
-
}
|
|
5872
|
-
const { idFieldName, passwordFieldName } = userField;
|
|
5873
|
-
const user = users.find((u) => u[idFieldName] === ctxUser.sub);
|
|
5874
|
-
if (!user) {
|
|
5875
|
-
throw new Error("Not authorized");
|
|
5876
|
-
}
|
|
5877
|
-
user[passwordFieldName] = {
|
|
5878
|
-
value: args.password,
|
|
5879
|
-
passwordChangeRequired: false
|
|
5880
|
-
};
|
|
5881
|
-
const params = {};
|
|
5882
|
-
set(
|
|
5883
|
-
params,
|
|
5884
|
-
userField.path.slice(1),
|
|
5885
|
-
// remove _rawData from users path
|
|
5886
|
-
users.map((u) => {
|
|
5887
|
-
if (user[idFieldName] === u[idFieldName]) {
|
|
5888
|
-
return user;
|
|
5889
|
-
}
|
|
5890
|
-
return {
|
|
5891
|
-
// don't overwrite other users' passwords
|
|
5892
|
-
...u,
|
|
5893
|
-
[passwordFieldName]: {
|
|
5894
|
-
...u[passwordFieldName],
|
|
5895
|
-
value: ""
|
|
5896
|
-
}
|
|
5897
|
-
};
|
|
5898
|
-
})
|
|
5899
|
-
);
|
|
5900
|
-
await resolver.updateResolveDocument({
|
|
5901
|
-
collection,
|
|
5902
|
-
args: { params },
|
|
5903
|
-
realPath,
|
|
5904
|
-
isCollectionSpecific: true,
|
|
5905
|
-
isAddPendingDocument: false
|
|
5932
|
+
return handleUpdatePassword({
|
|
5933
|
+
tinaSchema,
|
|
5934
|
+
resolver,
|
|
5935
|
+
password: args.password,
|
|
5936
|
+
info,
|
|
5937
|
+
ctxUser
|
|
5906
5938
|
});
|
|
5907
|
-
return true;
|
|
5908
5939
|
}
|
|
5909
5940
|
if (!lookup) {
|
|
5910
5941
|
return value;
|
|
@@ -6492,8 +6523,7 @@ var Database = class {
|
|
|
6492
6523
|
throw new TinaFetchError(`Error in PUT for ${filepath}`, {
|
|
6493
6524
|
originalError: error,
|
|
6494
6525
|
file: filepath,
|
|
6495
|
-
collection: collectionName
|
|
6496
|
-
stack: error.stack
|
|
6526
|
+
collection: collectionName
|
|
6497
6527
|
});
|
|
6498
6528
|
}
|
|
6499
6529
|
};
|
|
@@ -6853,8 +6883,7 @@ var Database = class {
|
|
|
6853
6883
|
throw new TinaQueryError({
|
|
6854
6884
|
originalError: error,
|
|
6855
6885
|
file: path7,
|
|
6856
|
-
collection: collection.name
|
|
6857
|
-
stack: error.stack
|
|
6886
|
+
collection: collection.name
|
|
6858
6887
|
});
|
|
6859
6888
|
}
|
|
6860
6889
|
throw error;
|
|
@@ -7384,8 +7413,7 @@ var _indexContent = async ({
|
|
|
7384
7413
|
throw new TinaFetchError(`Unable to seed ${filepath}`, {
|
|
7385
7414
|
originalError: error,
|
|
7386
7415
|
file: filepath,
|
|
7387
|
-
collection: collection?.name
|
|
7388
|
-
stack: error.stack
|
|
7416
|
+
collection: collection?.name
|
|
7389
7417
|
});
|
|
7390
7418
|
}
|
|
7391
7419
|
});
|