@oddington/sdk 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -553,37 +553,37 @@ var require_strings = __commonJS((exports) => {
|
|
|
553
553
|
exports.escapeRegExp = function(str) {
|
|
554
554
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
555
555
|
};
|
|
556
|
-
exports.cleanText = function(
|
|
557
|
-
return
|
|
556
|
+
exports.cleanText = function(text3) {
|
|
557
|
+
return text3.replace(/\t|\u0085|\u2028|\u2029/g, " ").replace(/[\b\v]/g, "");
|
|
558
558
|
};
|
|
559
559
|
exports.escapedNewlineChars = ["\\n", "\\f", "\\r", "\\u000B"];
|
|
560
560
|
exports.newlineChars = [`
|
|
561
561
|
`, "\f", "\r", "\v"];
|
|
562
|
-
exports.isNewlineChar = function(
|
|
563
|
-
return /^[\n\f\r\u000B]$/.test(
|
|
562
|
+
exports.isNewlineChar = function(text3) {
|
|
563
|
+
return /^[\n\f\r\u000B]$/.test(text3);
|
|
564
564
|
};
|
|
565
|
-
exports.lineSplit = function(
|
|
566
|
-
return
|
|
565
|
+
exports.lineSplit = function(text3) {
|
|
566
|
+
return text3.split(/[\n\f\r\u000B]/);
|
|
567
567
|
};
|
|
568
|
-
exports.mergeLines = function(
|
|
569
|
-
return
|
|
568
|
+
exports.mergeLines = function(text3) {
|
|
569
|
+
return text3.replace(/[\n\f\r\u000B]/g, " ");
|
|
570
570
|
};
|
|
571
|
-
exports.charAtIndex = function(
|
|
572
|
-
var cuFirst =
|
|
571
|
+
exports.charAtIndex = function(text3, index) {
|
|
572
|
+
var cuFirst = text3.charCodeAt(index);
|
|
573
573
|
var cuSecond;
|
|
574
574
|
var nextIndex = index + 1;
|
|
575
575
|
var length = 1;
|
|
576
|
-
if (cuFirst >= 55296 && cuFirst <= 56319 &&
|
|
577
|
-
cuSecond =
|
|
576
|
+
if (cuFirst >= 55296 && cuFirst <= 56319 && text3.length > nextIndex) {
|
|
577
|
+
cuSecond = text3.charCodeAt(nextIndex);
|
|
578
578
|
if (cuSecond >= 56320 && cuSecond <= 57343)
|
|
579
579
|
length = 2;
|
|
580
580
|
}
|
|
581
|
-
return [
|
|
581
|
+
return [text3.slice(index, index + length), length];
|
|
582
582
|
};
|
|
583
|
-
exports.charSplit = function(
|
|
583
|
+
exports.charSplit = function(text3) {
|
|
584
584
|
var chars = [];
|
|
585
|
-
for (var idx = 0, len =
|
|
586
|
-
var _a = exports.charAtIndex(
|
|
585
|
+
for (var idx = 0, len = text3.length;idx < len; ) {
|
|
586
|
+
var _a = exports.charAtIndex(text3, idx), c = _a[0], cLen = _a[1];
|
|
587
587
|
chars.push(c);
|
|
588
588
|
idx += cLen;
|
|
589
589
|
}
|
|
@@ -602,9 +602,9 @@ var require_strings = __commonJS((exports) => {
|
|
|
602
602
|
var breakRules = escapedRules.join("|");
|
|
603
603
|
return new RegExp("(" + newlineCharUnion + ")|((.*?)(" + breakRules + "))", "gm");
|
|
604
604
|
};
|
|
605
|
-
exports.breakTextIntoLines = function(
|
|
605
|
+
exports.breakTextIntoLines = function(text3, wordBreaks, maxWidth, computeWidthOfText) {
|
|
606
606
|
var regex = buildWordBreakRegex(wordBreaks);
|
|
607
|
-
var words = exports.cleanText(
|
|
607
|
+
var words = exports.cleanText(text3).match(regex);
|
|
608
608
|
var currLine = "";
|
|
609
609
|
var currWidth = 0;
|
|
610
610
|
var lines = [];
|
|
@@ -6135,21 +6135,21 @@ var require_PDFArray = __commonJS((exports) => {
|
|
|
6135
6135
|
PDFArray2.prototype.size = function() {
|
|
6136
6136
|
return this.array.length;
|
|
6137
6137
|
};
|
|
6138
|
-
PDFArray2.prototype.push = function(
|
|
6139
|
-
this.array.push(
|
|
6138
|
+
PDFArray2.prototype.push = function(object3) {
|
|
6139
|
+
this.array.push(object3);
|
|
6140
6140
|
};
|
|
6141
|
-
PDFArray2.prototype.insert = function(index,
|
|
6142
|
-
this.array.splice(index, 0,
|
|
6141
|
+
PDFArray2.prototype.insert = function(index, object3) {
|
|
6142
|
+
this.array.splice(index, 0, object3);
|
|
6143
6143
|
};
|
|
6144
|
-
PDFArray2.prototype.indexOf = function(
|
|
6145
|
-
var index = this.array.indexOf(
|
|
6144
|
+
PDFArray2.prototype.indexOf = function(object3) {
|
|
6145
|
+
var index = this.array.indexOf(object3);
|
|
6146
6146
|
return index === -1 ? undefined : index;
|
|
6147
6147
|
};
|
|
6148
6148
|
PDFArray2.prototype.remove = function(index) {
|
|
6149
6149
|
this.array.splice(index, 1);
|
|
6150
6150
|
};
|
|
6151
|
-
PDFArray2.prototype.set = function(idx,
|
|
6152
|
-
this.array[idx] =
|
|
6151
|
+
PDFArray2.prototype.set = function(idx, object3) {
|
|
6152
|
+
this.array[idx] = object3;
|
|
6153
6153
|
};
|
|
6154
6154
|
PDFArray2.prototype.get = function(index) {
|
|
6155
6155
|
return this.array[index];
|
|
@@ -7111,8 +7111,8 @@ var require_PDFContext = __commonJS((exports) => {
|
|
|
7111
7111
|
this.indirectObjects = new Map;
|
|
7112
7112
|
this.rng = rng_1.SimpleRNG.withSeed(1);
|
|
7113
7113
|
}
|
|
7114
|
-
PDFContext2.prototype.assign = function(ref,
|
|
7115
|
-
this.indirectObjects.set(ref,
|
|
7114
|
+
PDFContext2.prototype.assign = function(ref, object3) {
|
|
7115
|
+
this.indirectObjects.set(ref, object3);
|
|
7116
7116
|
if (ref.objectNumber > this.largestObjectNumber) {
|
|
7117
7117
|
this.largestObjectNumber = ref.objectNumber;
|
|
7118
7118
|
}
|
|
@@ -7121,9 +7121,9 @@ var require_PDFContext = __commonJS((exports) => {
|
|
|
7121
7121
|
this.largestObjectNumber += 1;
|
|
7122
7122
|
return PDFRef_1.default.of(this.largestObjectNumber);
|
|
7123
7123
|
};
|
|
7124
|
-
PDFContext2.prototype.register = function(
|
|
7124
|
+
PDFContext2.prototype.register = function(object3) {
|
|
7125
7125
|
var ref = this.nextRef();
|
|
7126
|
-
this.assign(ref,
|
|
7126
|
+
this.assign(ref, object3);
|
|
7127
7127
|
return ref;
|
|
7128
7128
|
};
|
|
7129
7129
|
PDFContext2.prototype.delete = function(ref) {
|
|
@@ -7173,8 +7173,8 @@ var require_PDFContext = __commonJS((exports) => {
|
|
|
7173
7173
|
PDFContext2.prototype.getObjectRef = function(pdfObject) {
|
|
7174
7174
|
var entries = Array.from(this.indirectObjects.entries());
|
|
7175
7175
|
for (var idx = 0, len = entries.length;idx < len; idx++) {
|
|
7176
|
-
var _a = entries[idx], ref = _a[0],
|
|
7177
|
-
if (
|
|
7176
|
+
var _a = entries[idx], ref = _a[0], object3 = _a[1];
|
|
7177
|
+
if (object3 === pdfObject) {
|
|
7178
7178
|
return ref;
|
|
7179
7179
|
}
|
|
7180
7180
|
}
|
|
@@ -7202,9 +7202,9 @@ var require_PDFContext = __commonJS((exports) => {
|
|
|
7202
7202
|
return array2;
|
|
7203
7203
|
} else {
|
|
7204
7204
|
var dict = PDFDict_1.default.withContext(this);
|
|
7205
|
-
var
|
|
7206
|
-
for (var idx = 0, len =
|
|
7207
|
-
var key =
|
|
7205
|
+
var keys3 = Object.keys(literal);
|
|
7206
|
+
for (var idx = 0, len = keys3.length;idx < len; idx++) {
|
|
7207
|
+
var key = keys3[idx];
|
|
7208
7208
|
var value = literal[key];
|
|
7209
7209
|
if (value !== undefined)
|
|
7210
7210
|
dict.set(PDFName_1.default.of(key), this.obj(value));
|
|
@@ -7492,8 +7492,8 @@ var require_PDFObjectCopier = __commonJS((exports) => {
|
|
|
7492
7492
|
function PDFObjectCopier2(src, dest) {
|
|
7493
7493
|
var _this = this;
|
|
7494
7494
|
this.traversedObjects = new Map;
|
|
7495
|
-
this.copy = function(
|
|
7496
|
-
return
|
|
7495
|
+
this.copy = function(object3) {
|
|
7496
|
+
return object3 instanceof PDFPageLeaf_1.default ? _this.copyPDFPage(object3) : object3 instanceof PDFDict_1.default ? _this.copyPDFDict(object3) : object3 instanceof PDFArray_1.default ? _this.copyPDFArray(object3) : object3 instanceof PDFStream_1.default ? _this.copyPDFStream(object3) : object3 instanceof PDFRef_1.default ? _this.copyPDFIndirectObject(object3) : object3.clone();
|
|
7497
7497
|
};
|
|
7498
7498
|
this.copyPDFPage = function(originalPage) {
|
|
7499
7499
|
var clonedPage = originalPage.clone();
|
|
@@ -7812,8 +7812,8 @@ var require_PDFObjectStream = __commonJS((exports) => {
|
|
|
7812
7812
|
PDFObjectStream2.prototype.getContentsString = function() {
|
|
7813
7813
|
var value = this.offsetsString;
|
|
7814
7814
|
for (var idx = 0, len = this.objects.length;idx < len; idx++) {
|
|
7815
|
-
var _a = this.objects[idx],
|
|
7816
|
-
value +=
|
|
7815
|
+
var _a = this.objects[idx], object3 = _a[1];
|
|
7816
|
+
value += object3 + `
|
|
7817
7817
|
`;
|
|
7818
7818
|
}
|
|
7819
7819
|
return value;
|
|
@@ -7822,8 +7822,8 @@ var require_PDFObjectStream = __commonJS((exports) => {
|
|
|
7822
7822
|
var buffer = new Uint8Array(this.getUnencodedContentsSize());
|
|
7823
7823
|
var offset = utils_1.copyStringIntoBuffer(this.offsetsString, buffer, 0);
|
|
7824
7824
|
for (var idx = 0, len = this.objects.length;idx < len; idx++) {
|
|
7825
|
-
var _a = this.objects[idx],
|
|
7826
|
-
offset +=
|
|
7825
|
+
var _a = this.objects[idx], object3 = _a[1];
|
|
7826
|
+
offset += object3.copyBytesInto(buffer, offset);
|
|
7827
7827
|
buffer[offset++] = CharCodes_1.default.Newline;
|
|
7828
7828
|
}
|
|
7829
7829
|
return buffer;
|
|
@@ -7843,9 +7843,9 @@ var require_PDFObjectStream = __commonJS((exports) => {
|
|
|
7843
7843
|
var offset = 0;
|
|
7844
7844
|
var offsets = new Array(this.objects.length);
|
|
7845
7845
|
for (var idx = 0, len = this.objects.length;idx < len; idx++) {
|
|
7846
|
-
var _a = this.objects[idx], ref = _a[0],
|
|
7846
|
+
var _a = this.objects[idx], ref = _a[0], object3 = _a[1];
|
|
7847
7847
|
offsets[idx] = [ref.objectNumber, offset];
|
|
7848
|
-
offset +=
|
|
7848
|
+
offset += object3.sizeInBytes() + 1;
|
|
7849
7849
|
}
|
|
7850
7850
|
return offsets;
|
|
7851
7851
|
};
|
|
@@ -7884,7 +7884,7 @@ var require_PDFWriter = __commonJS((exports) => {
|
|
|
7884
7884
|
}
|
|
7885
7885
|
PDFWriter2.prototype.serializeToBuffer = function() {
|
|
7886
7886
|
return tslib_1.__awaiter(this, undefined, undefined, function() {
|
|
7887
|
-
var _a, size, header, indirectObjects, xref, trailerDict, trailer, offset, buffer, idx, len, _b, ref,
|
|
7887
|
+
var _a, size, header, indirectObjects, xref, trailerDict, trailer, offset, buffer, idx, len, _b, ref, object3, objectNumber, generationNumber, n;
|
|
7888
7888
|
return tslib_1.__generator(this, function(_c) {
|
|
7889
7889
|
switch (_c.label) {
|
|
7890
7890
|
case 0:
|
|
@@ -7901,7 +7901,7 @@ var require_PDFWriter = __commonJS((exports) => {
|
|
|
7901
7901
|
case 2:
|
|
7902
7902
|
if (!(idx < len))
|
|
7903
7903
|
return [3, 5];
|
|
7904
|
-
_b = indirectObjects[idx], ref = _b[0],
|
|
7904
|
+
_b = indirectObjects[idx], ref = _b[0], object3 = _b[1];
|
|
7905
7905
|
objectNumber = String(ref.objectNumber);
|
|
7906
7906
|
offset += utils_1.copyStringIntoBuffer(objectNumber, buffer, offset);
|
|
7907
7907
|
buffer[offset++] = CharCodes_1.default.Space;
|
|
@@ -7912,7 +7912,7 @@ var require_PDFWriter = __commonJS((exports) => {
|
|
|
7912
7912
|
buffer[offset++] = CharCodes_1.default.b;
|
|
7913
7913
|
buffer[offset++] = CharCodes_1.default.j;
|
|
7914
7914
|
buffer[offset++] = CharCodes_1.default.Newline;
|
|
7915
|
-
offset +=
|
|
7915
|
+
offset += object3.copyBytesInto(buffer, offset);
|
|
7916
7916
|
buffer[offset++] = CharCodes_1.default.Newline;
|
|
7917
7917
|
buffer[offset++] = CharCodes_1.default.e;
|
|
7918
7918
|
buffer[offset++] = CharCodes_1.default.n;
|
|
@@ -7922,7 +7922,7 @@ var require_PDFWriter = __commonJS((exports) => {
|
|
|
7922
7922
|
buffer[offset++] = CharCodes_1.default.j;
|
|
7923
7923
|
buffer[offset++] = CharCodes_1.default.Newline;
|
|
7924
7924
|
buffer[offset++] = CharCodes_1.default.Newline;
|
|
7925
|
-
n =
|
|
7925
|
+
n = object3 instanceof PDFObjectStream_1.default ? object3.getObjectsCount() : 1;
|
|
7926
7926
|
if (!this.shouldWaitForTick(n))
|
|
7927
7927
|
return [3, 4];
|
|
7928
7928
|
return [4, utils_1.waitForTick()];
|
|
@@ -7949,9 +7949,9 @@ var require_PDFWriter = __commonJS((exports) => {
|
|
|
7949
7949
|
});
|
|
7950
7950
|
};
|
|
7951
7951
|
PDFWriter2.prototype.computeIndirectObjectSize = function(_a) {
|
|
7952
|
-
var ref = _a[0],
|
|
7952
|
+
var ref = _a[0], object3 = _a[1];
|
|
7953
7953
|
var refSize = ref.sizeInBytes() + 3;
|
|
7954
|
-
var objectSize =
|
|
7954
|
+
var objectSize = object3.sizeInBytes() + 9;
|
|
7955
7955
|
return refSize + objectSize;
|
|
7956
7956
|
};
|
|
7957
7957
|
PDFWriter2.prototype.createTrailerDict = function() {
|
|
@@ -8258,7 +8258,7 @@ var require_PDFStreamWriter = __commonJS((exports) => {
|
|
|
8258
8258
|
}
|
|
8259
8259
|
PDFStreamWriter2.prototype.computeBufferSize = function() {
|
|
8260
8260
|
return tslib_1.__awaiter(this, undefined, undefined, function() {
|
|
8261
|
-
var objectNumber, header, size, xrefStream, uncompressedObjects, compressedObjects, objectStreamRefs, indirectObjects, idx, len, indirectObject, ref,
|
|
8261
|
+
var objectNumber, header, size, xrefStream, uncompressedObjects, compressedObjects, objectStreamRefs, indirectObjects, idx, len, indirectObject, ref, object3, shouldNotCompress, chunk, objectStreamRef, idx, len, chunk, ref, objectStream, xrefStreamRef, xrefOffset, trailer;
|
|
8262
8262
|
return tslib_1.__generator(this, function(_a) {
|
|
8263
8263
|
switch (_a.label) {
|
|
8264
8264
|
case 0:
|
|
@@ -8276,8 +8276,8 @@ var require_PDFStreamWriter = __commonJS((exports) => {
|
|
|
8276
8276
|
if (!(idx < len))
|
|
8277
8277
|
return [3, 6];
|
|
8278
8278
|
indirectObject = indirectObjects[idx];
|
|
8279
|
-
ref = indirectObject[0],
|
|
8280
|
-
shouldNotCompress = ref === this.context.trailerInfo.Encrypt ||
|
|
8279
|
+
ref = indirectObject[0], object3 = indirectObject[1];
|
|
8280
|
+
shouldNotCompress = ref === this.context.trailerInfo.Encrypt || object3 instanceof PDFStream_1.default || object3 instanceof PDFInvalidObject_1.default || ref.generationNumber !== 0;
|
|
8281
8281
|
if (!shouldNotCompress)
|
|
8282
8282
|
return [3, 4];
|
|
8283
8283
|
uncompressedObjects.push(indirectObject);
|
|
@@ -8391,10 +8391,10 @@ var require_PDFHexString = __commonJS((exports) => {
|
|
|
8391
8391
|
return utils_1.pdfDocEncodingDecode(bytes);
|
|
8392
8392
|
};
|
|
8393
8393
|
PDFHexString2.prototype.decodeDate = function() {
|
|
8394
|
-
var
|
|
8395
|
-
var date = utils_1.parseDate(
|
|
8394
|
+
var text3 = this.decodeText();
|
|
8395
|
+
var date = utils_1.parseDate(text3);
|
|
8396
8396
|
if (!date)
|
|
8397
|
-
throw new errors_1.InvalidPDFDateStringError(
|
|
8397
|
+
throw new errors_1.InvalidPDFDateStringError(text3);
|
|
8398
8398
|
return date;
|
|
8399
8399
|
};
|
|
8400
8400
|
PDFHexString2.prototype.asString = function() {
|
|
@@ -8445,16 +8445,16 @@ var require_StandardFontEmbedder = __commonJS((exports) => {
|
|
|
8445
8445
|
this.fontName = this.font.FontName;
|
|
8446
8446
|
this.customName = customName;
|
|
8447
8447
|
}
|
|
8448
|
-
StandardFontEmbedder2.prototype.encodeText = function(
|
|
8449
|
-
var glyphs = this.encodeTextAsGlyphs(
|
|
8448
|
+
StandardFontEmbedder2.prototype.encodeText = function(text3) {
|
|
8449
|
+
var glyphs = this.encodeTextAsGlyphs(text3);
|
|
8450
8450
|
var hexCodes = new Array(glyphs.length);
|
|
8451
8451
|
for (var idx = 0, len = glyphs.length;idx < len; idx++) {
|
|
8452
8452
|
hexCodes[idx] = utils_1.toHexString(glyphs[idx].code);
|
|
8453
8453
|
}
|
|
8454
8454
|
return PDFHexString_1.default.of(hexCodes.join(""));
|
|
8455
8455
|
};
|
|
8456
|
-
StandardFontEmbedder2.prototype.widthOfTextAtSize = function(
|
|
8457
|
-
var glyphs = this.encodeTextAsGlyphs(
|
|
8456
|
+
StandardFontEmbedder2.prototype.widthOfTextAtSize = function(text3, size) {
|
|
8457
|
+
var glyphs = this.encodeTextAsGlyphs(text3);
|
|
8458
8458
|
var totalWidth = 0;
|
|
8459
8459
|
for (var idx = 0, len = glyphs.length;idx < len; idx++) {
|
|
8460
8460
|
var left = glyphs[idx].name;
|
|
@@ -8501,8 +8501,8 @@ var require_StandardFontEmbedder = __commonJS((exports) => {
|
|
|
8501
8501
|
StandardFontEmbedder2.prototype.widthOfGlyph = function(glyphName) {
|
|
8502
8502
|
return this.font.getWidthOfGlyph(glyphName) || 250;
|
|
8503
8503
|
};
|
|
8504
|
-
StandardFontEmbedder2.prototype.encodeTextAsGlyphs = function(
|
|
8505
|
-
var codePoints = Array.from(
|
|
8504
|
+
StandardFontEmbedder2.prototype.encodeTextAsGlyphs = function(text3) {
|
|
8505
|
+
var codePoints = Array.from(text3);
|
|
8506
8506
|
var glyphs = new Array(codePoints.length);
|
|
8507
8507
|
for (var idx = 0, len = codePoints.length;idx < len; idx++) {
|
|
8508
8508
|
var codePoint = utils_1.toCodePoint(codePoints[idx]);
|
|
@@ -8700,10 +8700,10 @@ var require_PDFString = __commonJS((exports) => {
|
|
|
8700
8700
|
return utils_1.pdfDocEncodingDecode(bytes);
|
|
8701
8701
|
};
|
|
8702
8702
|
PDFString2.prototype.decodeDate = function() {
|
|
8703
|
-
var
|
|
8704
|
-
var date = utils_1.parseDate(
|
|
8703
|
+
var text3 = this.decodeText();
|
|
8704
|
+
var date = utils_1.parseDate(text3);
|
|
8705
8705
|
if (!date)
|
|
8706
|
-
throw new errors_1.InvalidPDFDateStringError(
|
|
8706
|
+
throw new errors_1.InvalidPDFDateStringError(text3);
|
|
8707
8707
|
return date;
|
|
8708
8708
|
};
|
|
8709
8709
|
PDFString2.prototype.asString = function() {
|
|
@@ -8786,16 +8786,16 @@ var require_CustomFontEmbedder = __commonJS((exports) => {
|
|
|
8786
8786
|
});
|
|
8787
8787
|
});
|
|
8788
8788
|
};
|
|
8789
|
-
CustomFontEmbedder2.prototype.encodeText = function(
|
|
8790
|
-
var glyphs = this.font.layout(
|
|
8789
|
+
CustomFontEmbedder2.prototype.encodeText = function(text3) {
|
|
8790
|
+
var glyphs = this.font.layout(text3, this.fontFeatures).glyphs;
|
|
8791
8791
|
var hexCodes = new Array(glyphs.length);
|
|
8792
8792
|
for (var idx = 0, len = glyphs.length;idx < len; idx++) {
|
|
8793
8793
|
hexCodes[idx] = utils_1.toHexStringOfMinLength(glyphs[idx].id, 4);
|
|
8794
8794
|
}
|
|
8795
8795
|
return PDFHexString_1.default.of(hexCodes.join(""));
|
|
8796
8796
|
};
|
|
8797
|
-
CustomFontEmbedder2.prototype.widthOfTextAtSize = function(
|
|
8798
|
-
var glyphs = this.font.layout(
|
|
8797
|
+
CustomFontEmbedder2.prototype.widthOfTextAtSize = function(text3, size) {
|
|
8798
|
+
var glyphs = this.font.layout(text3, this.fontFeatures).glyphs;
|
|
8799
8799
|
var totalWidth = 0;
|
|
8800
8800
|
for (var idx = 0, len = glyphs.length;idx < len; idx++) {
|
|
8801
8801
|
totalWidth += glyphs[idx].advanceWidth * this.scale;
|
|
@@ -9006,8 +9006,8 @@ var require_CustomFontSubsetEmbedder = __commonJS((exports) => {
|
|
|
9006
9006
|
});
|
|
9007
9007
|
});
|
|
9008
9008
|
};
|
|
9009
|
-
CustomFontSubsetEmbedder2.prototype.encodeText = function(
|
|
9010
|
-
var glyphs = this.font.layout(
|
|
9009
|
+
CustomFontSubsetEmbedder2.prototype.encodeText = function(text3) {
|
|
9010
|
+
var glyphs = this.font.layout(text3, this.fontFeatures).glyphs;
|
|
9011
9011
|
var hexCodes = new Array(glyphs.length);
|
|
9012
9012
|
for (var idx = 0, len = glyphs.length;idx < len; idx++) {
|
|
9013
9013
|
var glyph = glyphs[idx];
|
|
@@ -9463,8 +9463,8 @@ var require_UPNG = __commonJS((exports) => {
|
|
|
9463
9463
|
out.tabs[type] = {};
|
|
9464
9464
|
var nz = bin.nextZero(data, offset);
|
|
9465
9465
|
var keyw = bin.readASCII(data, offset, nz - offset);
|
|
9466
|
-
var
|
|
9467
|
-
out.tabs[type][keyw] =
|
|
9466
|
+
var text3 = bin.readASCII(data, nz + 1, offset + len - nz - 1);
|
|
9467
|
+
out.tabs[type][keyw] = text3;
|
|
9468
9468
|
} else if (type == "iTXt") {
|
|
9469
9469
|
if (out.tabs[type] == null)
|
|
9470
9470
|
out.tabs[type] = {};
|
|
@@ -9480,8 +9480,8 @@ var require_UPNG = __commonJS((exports) => {
|
|
|
9480
9480
|
nz = bin.nextZero(data, off);
|
|
9481
9481
|
var tkeyw = bin.readUTF8(data, off, nz - off);
|
|
9482
9482
|
off = nz + 1;
|
|
9483
|
-
var
|
|
9484
|
-
out.tabs[type][keyw] =
|
|
9483
|
+
var text3 = bin.readUTF8(data, off, len - (off - offset));
|
|
9484
|
+
out.tabs[type][keyw] = text3;
|
|
9485
9485
|
} else if (type == "PLTE") {
|
|
9486
9486
|
out.tabs[type] = bin.readBytes(data, offset, len);
|
|
9487
9487
|
} else if (type == "hIST") {
|
|
@@ -13306,9 +13306,9 @@ var require_PDFWidgetAnnotation = __commonJS((exports) => {
|
|
|
13306
13306
|
var _a;
|
|
13307
13307
|
var normal = (_a = this.getAppearances()) === null || _a === undefined ? undefined : _a.normal;
|
|
13308
13308
|
if (normal instanceof PDFDict_1.default) {
|
|
13309
|
-
var
|
|
13310
|
-
for (var idx = 0, len =
|
|
13311
|
-
var key =
|
|
13309
|
+
var keys3 = normal.keys();
|
|
13310
|
+
for (var idx = 0, len = keys3.length;idx < len; idx++) {
|
|
13311
|
+
var key = keys3[idx];
|
|
13312
13312
|
if (key !== PDFName_1.default.of("Off"))
|
|
13313
13313
|
return key;
|
|
13314
13314
|
}
|
|
@@ -14091,28 +14091,28 @@ var require_PDFAcroForm = __commonJS((exports) => {
|
|
|
14091
14091
|
this.dict = dict;
|
|
14092
14092
|
}
|
|
14093
14093
|
PDFAcroForm2.prototype.Fields = function() {
|
|
14094
|
-
var
|
|
14095
|
-
if (
|
|
14096
|
-
return
|
|
14094
|
+
var fields3 = this.dict.lookup(PDFName_1.default.of("Fields"));
|
|
14095
|
+
if (fields3 instanceof PDFArray_1.default)
|
|
14096
|
+
return fields3;
|
|
14097
14097
|
return;
|
|
14098
14098
|
};
|
|
14099
14099
|
PDFAcroForm2.prototype.getFields = function() {
|
|
14100
14100
|
var Fields = this.normalizedEntries().Fields;
|
|
14101
|
-
var
|
|
14101
|
+
var fields3 = new Array(Fields.size());
|
|
14102
14102
|
for (var idx = 0, len = Fields.size();idx < len; idx++) {
|
|
14103
14103
|
var ref = Fields.get(idx);
|
|
14104
14104
|
var dict = Fields.lookup(idx, PDFDict_1.default);
|
|
14105
|
-
|
|
14105
|
+
fields3[idx] = [utils_1.createPDFAcroField(dict, ref), ref];
|
|
14106
14106
|
}
|
|
14107
|
-
return
|
|
14107
|
+
return fields3;
|
|
14108
14108
|
};
|
|
14109
14109
|
PDFAcroForm2.prototype.getAllFields = function() {
|
|
14110
14110
|
var allFields = [];
|
|
14111
|
-
var pushFields = function(
|
|
14112
|
-
if (!
|
|
14111
|
+
var pushFields = function(fields3) {
|
|
14112
|
+
if (!fields3)
|
|
14113
14113
|
return;
|
|
14114
|
-
for (var idx = 0, len =
|
|
14115
|
-
var field =
|
|
14114
|
+
for (var idx = 0, len = fields3.length;idx < len; idx++) {
|
|
14115
|
+
var field = fields3[idx];
|
|
14116
14116
|
allFields.push(field);
|
|
14117
14117
|
var fieldModel = field[0];
|
|
14118
14118
|
if (fieldModel instanceof PDFAcroNonTerminal_1.default) {
|
|
@@ -14129,13 +14129,13 @@ var require_PDFAcroForm = __commonJS((exports) => {
|
|
|
14129
14129
|
};
|
|
14130
14130
|
PDFAcroForm2.prototype.removeField = function(field) {
|
|
14131
14131
|
var parent = field.getParent();
|
|
14132
|
-
var
|
|
14133
|
-
var index =
|
|
14134
|
-
if (
|
|
14132
|
+
var fields3 = parent === undefined ? this.normalizedEntries().Fields : parent.Kids();
|
|
14133
|
+
var index = fields3 === null || fields3 === undefined ? undefined : fields3.indexOf(field.ref);
|
|
14134
|
+
if (fields3 === undefined || index === undefined) {
|
|
14135
14135
|
throw new Error("Tried to remove inexistent field " + field.getFullyQualifiedName());
|
|
14136
14136
|
}
|
|
14137
|
-
|
|
14138
|
-
if (parent !== undefined &&
|
|
14137
|
+
fields3.remove(index);
|
|
14138
|
+
if (parent !== undefined && fields3.size() === 0) {
|
|
14139
14139
|
this.removeField(parent);
|
|
14140
14140
|
}
|
|
14141
14141
|
};
|
|
@@ -14974,7 +14974,7 @@ var require_PDFObjectStreamParser = __commonJS((exports) => {
|
|
|
14974
14974
|
}
|
|
14975
14975
|
PDFObjectStreamParser2.prototype.parseIntoContext = function() {
|
|
14976
14976
|
return tslib_1.__awaiter(this, undefined, undefined, function() {
|
|
14977
|
-
var offsetsAndObjectNumbers, idx, len, _a, objectNumber, offset,
|
|
14977
|
+
var offsetsAndObjectNumbers, idx, len, _a, objectNumber, offset, object3, ref;
|
|
14978
14978
|
return tslib_1.__generator(this, function(_b) {
|
|
14979
14979
|
switch (_b.label) {
|
|
14980
14980
|
case 0:
|
|
@@ -14990,9 +14990,9 @@ var require_PDFObjectStreamParser = __commonJS((exports) => {
|
|
|
14990
14990
|
return [3, 4];
|
|
14991
14991
|
_a = offsetsAndObjectNumbers[idx], objectNumber = _a.objectNumber, offset = _a.offset;
|
|
14992
14992
|
this.bytes.moveTo(this.firstOffset + offset);
|
|
14993
|
-
|
|
14993
|
+
object3 = this.parseObject();
|
|
14994
14994
|
ref = PDFRef_1.default.of(objectNumber, 0);
|
|
14995
|
-
this.context.assign(ref,
|
|
14995
|
+
this.context.assign(ref, object3);
|
|
14996
14996
|
if (!this.shouldWaitForTick())
|
|
14997
14997
|
return [3, 3];
|
|
14998
14998
|
return [4, utils_1.waitForTick()];
|
|
@@ -15203,8 +15203,8 @@ var require_PDFParser = __commonJS((exports) => {
|
|
|
15203
15203
|
if (!isValidCatalog(catalog)) {
|
|
15204
15204
|
var indirectObjects = this.context.enumerateIndirectObjects();
|
|
15205
15205
|
for (var idx = 0, len = indirectObjects.length;idx < len; idx++) {
|
|
15206
|
-
var _a = indirectObjects[idx], ref = _a[0],
|
|
15207
|
-
if (isValidCatalog(
|
|
15206
|
+
var _a = indirectObjects[idx], ref = _a[0], object3 = _a[1];
|
|
15207
|
+
if (isValidCatalog(object3)) {
|
|
15208
15208
|
this.context.trailerInfo.Root = ref;
|
|
15209
15209
|
}
|
|
15210
15210
|
}
|
|
@@ -15247,26 +15247,26 @@ var require_PDFParser = __commonJS((exports) => {
|
|
|
15247
15247
|
};
|
|
15248
15248
|
PDFParser2.prototype.parseIndirectObject = function() {
|
|
15249
15249
|
return tslib_1.__awaiter(this, undefined, undefined, function() {
|
|
15250
|
-
var ref,
|
|
15250
|
+
var ref, object3;
|
|
15251
15251
|
return tslib_1.__generator(this, function(_a) {
|
|
15252
15252
|
switch (_a.label) {
|
|
15253
15253
|
case 0:
|
|
15254
15254
|
ref = this.parseIndirectObjectHeader();
|
|
15255
15255
|
this.skipWhitespaceAndComments();
|
|
15256
|
-
|
|
15256
|
+
object3 = this.parseObject();
|
|
15257
15257
|
this.skipWhitespaceAndComments();
|
|
15258
15258
|
this.matchKeyword(Keywords_1.Keywords.endobj);
|
|
15259
|
-
if (!(
|
|
15259
|
+
if (!(object3 instanceof PDFRawStream_1.default && object3.dict.lookup(PDFName_1.default.of("Type")) === PDFName_1.default.of("ObjStm")))
|
|
15260
15260
|
return [3, 2];
|
|
15261
|
-
return [4, PDFObjectStreamParser_1.default.forStream(
|
|
15261
|
+
return [4, PDFObjectStreamParser_1.default.forStream(object3, this.shouldWaitForTick).parseIntoContext()];
|
|
15262
15262
|
case 1:
|
|
15263
15263
|
_a.sent();
|
|
15264
15264
|
return [3, 3];
|
|
15265
15265
|
case 2:
|
|
15266
|
-
if (
|
|
15267
|
-
PDFXRefStreamParser_1.default.forStream(
|
|
15266
|
+
if (object3 instanceof PDFRawStream_1.default && object3.dict.lookup(PDFName_1.default.of("Type")) === PDFName_1.default.of("XRef")) {
|
|
15267
|
+
PDFXRefStreamParser_1.default.forStream(object3).parseIntoContext();
|
|
15268
15268
|
} else {
|
|
15269
|
-
this.context.assign(ref,
|
|
15269
|
+
this.context.assign(ref, object3);
|
|
15270
15270
|
}
|
|
15271
15271
|
_a.label = 3;
|
|
15272
15272
|
case 3:
|
|
@@ -15297,8 +15297,8 @@ var require_PDFParser = __commonJS((exports) => {
|
|
|
15297
15297
|
if (failed)
|
|
15298
15298
|
throw new errors_1.PDFInvalidObjectParsingError(startPos);
|
|
15299
15299
|
var end = this.bytes.offset() - Keywords_1.Keywords.endobj.length;
|
|
15300
|
-
var
|
|
15301
|
-
this.context.assign(ref,
|
|
15300
|
+
var object3 = PDFInvalidObject_1.default.of(this.bytes.slice(start, end));
|
|
15301
|
+
this.context.assign(ref, object3);
|
|
15302
15302
|
return ref;
|
|
15303
15303
|
};
|
|
15304
15304
|
PDFParser2.prototype.parseIndirectObjects = function() {
|
|
@@ -15921,8 +15921,8 @@ var require_operators = __commonJS((exports) => {
|
|
|
15921
15921
|
exports.moveText = function(x, y) {
|
|
15922
15922
|
return core_1.PDFOperator.of(core_1.PDFOperatorNames.MoveText, [objects_1.asPDFNumber(x), objects_1.asPDFNumber(y)]);
|
|
15923
15923
|
};
|
|
15924
|
-
exports.showText = function(
|
|
15925
|
-
return core_1.PDFOperator.of(core_1.PDFOperatorNames.ShowText, [
|
|
15924
|
+
exports.showText = function(text3) {
|
|
15925
|
+
return core_1.PDFOperator.of(core_1.PDFOperatorNames.ShowText, [text3]);
|
|
15926
15926
|
};
|
|
15927
15927
|
exports.beginText = function() {
|
|
15928
15928
|
return core_1.PDFOperator.of(core_1.PDFOperatorNames.BeginText);
|
|
@@ -17143,9 +17143,9 @@ var require_layout = __commonJS((exports) => {
|
|
|
17143
17143
|
remainder: undefined
|
|
17144
17144
|
};
|
|
17145
17145
|
};
|
|
17146
|
-
exports.layoutMultilineText = function(
|
|
17146
|
+
exports.layoutMultilineText = function(text3, _a) {
|
|
17147
17147
|
var { alignment, fontSize, font, bounds } = _a;
|
|
17148
|
-
var lines = utils_1.lineSplit(utils_1.cleanText(
|
|
17148
|
+
var lines = utils_1.lineSplit(utils_1.cleanText(text3));
|
|
17149
17149
|
if (fontSize === undefined || fontSize === 0) {
|
|
17150
17150
|
fontSize = computeFontSize(lines, font, bounds, true);
|
|
17151
17151
|
}
|
|
@@ -17187,9 +17187,9 @@ var require_layout = __commonJS((exports) => {
|
|
|
17187
17187
|
}
|
|
17188
17188
|
};
|
|
17189
17189
|
};
|
|
17190
|
-
exports.layoutCombedText = function(
|
|
17190
|
+
exports.layoutCombedText = function(text3, _a) {
|
|
17191
17191
|
var { fontSize, font, bounds, cellCount } = _a;
|
|
17192
|
-
var line = utils_1.mergeLines(utils_1.cleanText(
|
|
17192
|
+
var line = utils_1.mergeLines(utils_1.cleanText(text3));
|
|
17193
17193
|
if (line.length > cellCount) {
|
|
17194
17194
|
throw new errors_1.CombedTextLayoutError(line.length, cellCount);
|
|
17195
17195
|
}
|
|
@@ -17235,9 +17235,9 @@ var require_layout = __commonJS((exports) => {
|
|
|
17235
17235
|
}
|
|
17236
17236
|
};
|
|
17237
17237
|
};
|
|
17238
|
-
exports.layoutSinglelineText = function(
|
|
17238
|
+
exports.layoutSinglelineText = function(text3, _a) {
|
|
17239
17239
|
var { alignment, fontSize, font, bounds } = _a;
|
|
17240
|
-
var line = utils_1.mergeLines(utils_1.cleanText(
|
|
17240
|
+
var line = utils_1.mergeLines(utils_1.cleanText(text3));
|
|
17241
17241
|
if (fontSize === undefined || fontSize === 0) {
|
|
17242
17242
|
fontSize = computeFontSize([line], font, bounds);
|
|
17243
17243
|
}
|
|
@@ -17461,7 +17461,7 @@ var require_appearances = __commonJS((exports) => {
|
|
|
17461
17461
|
var rectangle = widget.getRectangle();
|
|
17462
17462
|
var ap = widget.getAppearanceCharacteristics();
|
|
17463
17463
|
var bs = widget.getBorderStyle();
|
|
17464
|
-
var
|
|
17464
|
+
var text3 = (_a = textField.getText()) !== null && _a !== undefined ? _a : "";
|
|
17465
17465
|
var borderWidth = (_b = bs === null || bs === undefined ? undefined : bs.getWidth()) !== null && _b !== undefined ? _b : 0;
|
|
17466
17466
|
var rotation = rotations_1.reduceRotation(ap === null || ap === undefined ? undefined : ap.getRotation());
|
|
17467
17467
|
var _e = rotations_1.adjustDimsForRotation(rectangle, rotation), width = _e.width, height = _e.height;
|
|
@@ -17479,7 +17479,7 @@ var require_appearances = __commonJS((exports) => {
|
|
|
17479
17479
|
height: height - (borderWidth + padding) * 2
|
|
17480
17480
|
};
|
|
17481
17481
|
if (textField.isMultiline()) {
|
|
17482
|
-
var layout = layout_1.layoutMultilineText(
|
|
17482
|
+
var layout = layout_1.layoutMultilineText(text3, {
|
|
17483
17483
|
alignment: textField.getAlignment(),
|
|
17484
17484
|
fontSize: widgetFontSize !== null && widgetFontSize !== undefined ? widgetFontSize : fieldFontSize,
|
|
17485
17485
|
font,
|
|
@@ -17488,7 +17488,7 @@ var require_appearances = __commonJS((exports) => {
|
|
|
17488
17488
|
textLines = layout.lines;
|
|
17489
17489
|
fontSize = layout.fontSize;
|
|
17490
17490
|
} else if (textField.isCombed()) {
|
|
17491
|
-
var layout = layout_1.layoutCombedText(
|
|
17491
|
+
var layout = layout_1.layoutCombedText(text3, {
|
|
17492
17492
|
fontSize: widgetFontSize !== null && widgetFontSize !== undefined ? widgetFontSize : fieldFontSize,
|
|
17493
17493
|
font,
|
|
17494
17494
|
bounds,
|
|
@@ -17497,7 +17497,7 @@ var require_appearances = __commonJS((exports) => {
|
|
|
17497
17497
|
textLines = layout.cells;
|
|
17498
17498
|
fontSize = layout.fontSize;
|
|
17499
17499
|
} else {
|
|
17500
|
-
var layout = layout_1.layoutSinglelineText(
|
|
17500
|
+
var layout = layout_1.layoutSinglelineText(text3, {
|
|
17501
17501
|
alignment: textField.getAlignment(),
|
|
17502
17502
|
fontSize: widgetFontSize !== null && widgetFontSize !== undefined ? widgetFontSize : fieldFontSize,
|
|
17503
17503
|
font,
|
|
@@ -17537,7 +17537,7 @@ var require_appearances = __commonJS((exports) => {
|
|
|
17537
17537
|
var rectangle = widget.getRectangle();
|
|
17538
17538
|
var ap = widget.getAppearanceCharacteristics();
|
|
17539
17539
|
var bs = widget.getBorderStyle();
|
|
17540
|
-
var
|
|
17540
|
+
var text3 = (_a = dropdown.getSelected()[0]) !== null && _a !== undefined ? _a : "";
|
|
17541
17541
|
var borderWidth = (_b = bs === null || bs === undefined ? undefined : bs.getWidth()) !== null && _b !== undefined ? _b : 0;
|
|
17542
17542
|
var rotation = rotations_1.reduceRotation(ap === null || ap === undefined ? undefined : ap.getRotation());
|
|
17543
17543
|
var _d = rotations_1.adjustDimsForRotation(rectangle, rotation), width = _d.width, height = _d.height;
|
|
@@ -17552,7 +17552,7 @@ var require_appearances = __commonJS((exports) => {
|
|
|
17552
17552
|
width: width - (borderWidth + padding) * 2,
|
|
17553
17553
|
height: height - (borderWidth + padding) * 2
|
|
17554
17554
|
};
|
|
17555
|
-
var _e = layout_1.layoutSinglelineText(
|
|
17555
|
+
var _e = layout_1.layoutSinglelineText(text3, {
|
|
17556
17556
|
alignment: alignment_1.TextAlignment.Left,
|
|
17557
17557
|
fontSize: widgetFontSize !== null && widgetFontSize !== undefined ? widgetFontSize : fieldFontSize,
|
|
17558
17558
|
font,
|
|
@@ -17600,11 +17600,11 @@ var require_appearances = __commonJS((exports) => {
|
|
|
17600
17600
|
var selected = optionList.getSelected();
|
|
17601
17601
|
if (optionList.isSorted())
|
|
17602
17602
|
options.sort();
|
|
17603
|
-
var
|
|
17603
|
+
var text3 = "";
|
|
17604
17604
|
for (var idx = 0, len = options.length;idx < len; idx++) {
|
|
17605
|
-
|
|
17605
|
+
text3 += options[idx];
|
|
17606
17606
|
if (idx < len - 1)
|
|
17607
|
-
|
|
17607
|
+
text3 += `
|
|
17608
17608
|
`;
|
|
17609
17609
|
}
|
|
17610
17610
|
var padding = 1;
|
|
@@ -17614,7 +17614,7 @@ var require_appearances = __commonJS((exports) => {
|
|
|
17614
17614
|
width: width - (borderWidth + padding) * 2,
|
|
17615
17615
|
height: height - (borderWidth + padding) * 2
|
|
17616
17616
|
};
|
|
17617
|
-
var _d = layout_1.layoutMultilineText(
|
|
17617
|
+
var _d = layout_1.layoutMultilineText(text3, {
|
|
17618
17618
|
alignment: alignment_1.TextAlignment.Left,
|
|
17619
17619
|
fontSize: widgetFontSize !== null && widgetFontSize !== undefined ? widgetFontSize : fieldFontSize,
|
|
17620
17620
|
font,
|
|
@@ -17726,15 +17726,15 @@ var require_PDFFont = __commonJS((exports) => {
|
|
|
17726
17726
|
this.name = embedder.fontName;
|
|
17727
17727
|
this.embedder = embedder;
|
|
17728
17728
|
}
|
|
17729
|
-
PDFFont2.prototype.encodeText = function(
|
|
17730
|
-
utils_1.assertIs(
|
|
17729
|
+
PDFFont2.prototype.encodeText = function(text3) {
|
|
17730
|
+
utils_1.assertIs(text3, "text", ["string"]);
|
|
17731
17731
|
this.modified = true;
|
|
17732
|
-
return this.embedder.encodeText(
|
|
17732
|
+
return this.embedder.encodeText(text3);
|
|
17733
17733
|
};
|
|
17734
|
-
PDFFont2.prototype.widthOfTextAtSize = function(
|
|
17735
|
-
utils_1.assertIs(
|
|
17734
|
+
PDFFont2.prototype.widthOfTextAtSize = function(text3, size) {
|
|
17735
|
+
utils_1.assertIs(text3, "text", ["string"]);
|
|
17736
17736
|
utils_1.assertIs(size, "size", ["number"]);
|
|
17737
|
-
return this.embedder.widthOfTextAtSize(
|
|
17737
|
+
return this.embedder.widthOfTextAtSize(text3, size);
|
|
17738
17738
|
};
|
|
17739
17739
|
PDFFont2.prototype.heightAtSize = function(size, options) {
|
|
17740
17740
|
var _a;
|
|
@@ -18817,16 +18817,16 @@ var require_PDFTextField = __commonJS((exports) => {
|
|
|
18817
18817
|
}
|
|
18818
18818
|
return value === null || value === undefined ? undefined : value.decodeText();
|
|
18819
18819
|
};
|
|
18820
|
-
PDFTextField2.prototype.setText = function(
|
|
18821
|
-
utils_1.assertOrUndefined(
|
|
18820
|
+
PDFTextField2.prototype.setText = function(text3) {
|
|
18821
|
+
utils_1.assertOrUndefined(text3, "text", ["string"]);
|
|
18822
18822
|
var maxLength = this.getMaxLength();
|
|
18823
|
-
if (maxLength !== undefined &&
|
|
18824
|
-
throw new errors_1.ExceededMaxLengthError(
|
|
18823
|
+
if (maxLength !== undefined && text3 && text3.length > maxLength) {
|
|
18824
|
+
throw new errors_1.ExceededMaxLengthError(text3.length, maxLength, this.getName());
|
|
18825
18825
|
}
|
|
18826
18826
|
this.markAsDirty();
|
|
18827
18827
|
this.disableRichFormatting();
|
|
18828
|
-
if (
|
|
18829
|
-
this.acroField.setValue(core_1.PDFHexString.fromText(
|
|
18828
|
+
if (text3) {
|
|
18829
|
+
this.acroField.setValue(core_1.PDFHexString.fromText(text3));
|
|
18830
18830
|
} else {
|
|
18831
18831
|
this.acroField.removeValue();
|
|
18832
18832
|
}
|
|
@@ -18849,9 +18849,9 @@ var require_PDFTextField = __commonJS((exports) => {
|
|
|
18849
18849
|
if (maxLength === undefined) {
|
|
18850
18850
|
this.acroField.removeMaxLength();
|
|
18851
18851
|
} else {
|
|
18852
|
-
var
|
|
18853
|
-
if (
|
|
18854
|
-
throw new errors_1.InvalidMaxLengthError(
|
|
18852
|
+
var text3 = this.getText();
|
|
18853
|
+
if (text3 && text3.length > maxLength) {
|
|
18854
|
+
throw new errors_1.InvalidMaxLengthError(text3.length, maxLength, this.getName());
|
|
18855
18855
|
}
|
|
18856
18856
|
this.acroField.setMaxLength(maxLength);
|
|
18857
18857
|
}
|
|
@@ -19086,20 +19086,20 @@ var require_PDFForm = __commonJS((exports) => {
|
|
|
19086
19086
|
};
|
|
19087
19087
|
PDFForm2.prototype.getFields = function() {
|
|
19088
19088
|
var allFields = this.acroForm.getAllFields();
|
|
19089
|
-
var
|
|
19089
|
+
var fields3 = [];
|
|
19090
19090
|
for (var idx = 0, len = allFields.length;idx < len; idx++) {
|
|
19091
19091
|
var _a = allFields[idx], acroField = _a[0], ref = _a[1];
|
|
19092
19092
|
var field = convertToPDFField(acroField, ref, this.doc);
|
|
19093
19093
|
if (field)
|
|
19094
|
-
|
|
19094
|
+
fields3.push(field);
|
|
19095
19095
|
}
|
|
19096
|
-
return
|
|
19096
|
+
return fields3;
|
|
19097
19097
|
};
|
|
19098
19098
|
PDFForm2.prototype.getFieldMaybe = function(name) {
|
|
19099
19099
|
utils_1.assertIs(name, "name", ["string"]);
|
|
19100
|
-
var
|
|
19101
|
-
for (var idx = 0, len =
|
|
19102
|
-
var field =
|
|
19100
|
+
var fields3 = this.getFields();
|
|
19101
|
+
for (var idx = 0, len = fields3.length;idx < len; idx++) {
|
|
19102
|
+
var field = fields3[idx];
|
|
19103
19103
|
if (field.getName() === name)
|
|
19104
19104
|
return field;
|
|
19105
19105
|
}
|
|
@@ -19210,10 +19210,10 @@ var require_PDFForm = __commonJS((exports) => {
|
|
|
19210
19210
|
utils_1.assertIs(name, "name", ["string"]);
|
|
19211
19211
|
var nameParts = splitFieldName(name);
|
|
19212
19212
|
var parent = this.findOrCreateNonTerminals(nameParts.nonTerminal);
|
|
19213
|
-
var
|
|
19214
|
-
|
|
19215
|
-
addFieldToParent(parent, [
|
|
19216
|
-
return PDFTextField_1.default.of(
|
|
19213
|
+
var text3 = core_1.PDFAcroText.create(this.doc.context);
|
|
19214
|
+
text3.setPartialName(nameParts.terminal);
|
|
19215
|
+
addFieldToParent(parent, [text3, text3.ref], nameParts.terminal);
|
|
19216
|
+
return PDFTextField_1.default.of(text3, text3.ref, this.doc);
|
|
19217
19217
|
};
|
|
19218
19218
|
PDFForm2.prototype.flatten = function(options) {
|
|
19219
19219
|
if (options === undefined) {
|
|
@@ -19222,9 +19222,9 @@ var require_PDFForm = __commonJS((exports) => {
|
|
|
19222
19222
|
if (options.updateFieldAppearances) {
|
|
19223
19223
|
this.updateFieldAppearances();
|
|
19224
19224
|
}
|
|
19225
|
-
var
|
|
19226
|
-
for (var i = 0, lenFields =
|
|
19227
|
-
var field =
|
|
19225
|
+
var fields3 = this.getFields();
|
|
19226
|
+
for (var i = 0, lenFields = fields3.length;i < lenFields; i++) {
|
|
19227
|
+
var field = fields3[i];
|
|
19228
19228
|
var widgets = field.acroField.getWidgets();
|
|
19229
19229
|
for (var j = 0, lenWidgets = widgets.length;j < lenWidgets; j++) {
|
|
19230
19230
|
var widget = widgets[j];
|
|
@@ -19271,9 +19271,9 @@ var require_PDFForm = __commonJS((exports) => {
|
|
|
19271
19271
|
PDFForm2.prototype.updateFieldAppearances = function(font) {
|
|
19272
19272
|
utils_1.assertOrUndefined(font, "font", [[PDFFont_1.default, "PDFFont"]]);
|
|
19273
19273
|
font = font !== null && font !== undefined ? font : this.getDefaultFont();
|
|
19274
|
-
var
|
|
19275
|
-
for (var idx = 0, len =
|
|
19276
|
-
var field =
|
|
19274
|
+
var fields3 = this.getFields();
|
|
19275
|
+
for (var idx = 0, len = fields3.length;idx < len; idx++) {
|
|
19276
|
+
var field = fields3[idx];
|
|
19277
19277
|
if (field.needsAppearancesUpdate()) {
|
|
19278
19278
|
field.defaultUpdateAppearances(font);
|
|
19279
19279
|
}
|
|
@@ -19351,9 +19351,9 @@ var require_PDFForm = __commonJS((exports) => {
|
|
|
19351
19351
|
return nonTerminal;
|
|
19352
19352
|
};
|
|
19353
19353
|
PDFForm2.prototype.findNonTerminal = function(partialName, parent) {
|
|
19354
|
-
var
|
|
19355
|
-
for (var idx = 0, len =
|
|
19356
|
-
var _a =
|
|
19354
|
+
var fields3 = parent instanceof core_1.PDFAcroForm ? this.acroForm.getFields() : core_1.createPDFAcroFields(parent.Kids());
|
|
19355
|
+
for (var idx = 0, len = fields3.length;idx < len; idx++) {
|
|
19356
|
+
var _a = fields3[idx], field = _a[0], ref = _a[1];
|
|
19357
19357
|
if (field.getPartialName() === partialName) {
|
|
19358
19358
|
if (field instanceof core_1.PDFAcroNonTerminal)
|
|
19359
19359
|
return [field, ref];
|
|
@@ -19408,9 +19408,9 @@ var require_PDFForm = __commonJS((exports) => {
|
|
|
19408
19408
|
var parent = _a[0], parentRef = _a[1];
|
|
19409
19409
|
var field = _b[0], fieldRef = _b[1];
|
|
19410
19410
|
var entries = parent.normalizedEntries();
|
|
19411
|
-
var
|
|
19412
|
-
for (var idx = 0, len =
|
|
19413
|
-
if (
|
|
19411
|
+
var fields3 = core_1.createPDFAcroFields("Kids" in entries ? entries.Kids : entries.Fields);
|
|
19412
|
+
for (var idx = 0, len = fields3.length;idx < len; idx++) {
|
|
19413
|
+
if (fields3[idx][0].getPartialName() === partialName) {
|
|
19414
19414
|
throw new errors_1.FieldAlreadyExistsError(partialName);
|
|
19415
19415
|
}
|
|
19416
19416
|
}
|
|
@@ -20608,12 +20608,12 @@ var require_PDFPage = __commonJS((exports) => {
|
|
|
20608
20608
|
var contentStream = this.getContentStream();
|
|
20609
20609
|
contentStream.push.apply(contentStream, operator);
|
|
20610
20610
|
};
|
|
20611
|
-
PDFPage2.prototype.drawText = function(
|
|
20611
|
+
PDFPage2.prototype.drawText = function(text3, options) {
|
|
20612
20612
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
20613
20613
|
if (options === undefined) {
|
|
20614
20614
|
options = {};
|
|
20615
20615
|
}
|
|
20616
|
-
utils_1.assertIs(
|
|
20616
|
+
utils_1.assertIs(text3, "text", ["string"]);
|
|
20617
20617
|
utils_1.assertOrUndefined(options.color, "options.color", [[Object, "Color"]]);
|
|
20618
20618
|
utils_1.assertRangeOrUndefined(options.opacity, "opacity.opacity", 0, 1);
|
|
20619
20619
|
utils_1.assertOrUndefined(options.font, "options.font", [[PDFFont_1.default, "PDFFont"]]);
|
|
@@ -20633,7 +20633,7 @@ var require_PDFPage = __commonJS((exports) => {
|
|
|
20633
20633
|
var textWidth = function(t) {
|
|
20634
20634
|
return newFont.widthOfTextAtSize(t, fontSize);
|
|
20635
20635
|
};
|
|
20636
|
-
var lines = options.maxWidth === undefined ? utils_1.lineSplit(utils_1.cleanText(
|
|
20636
|
+
var lines = options.maxWidth === undefined ? utils_1.lineSplit(utils_1.cleanText(text3)) : utils_1.breakTextIntoLines(text3, wordBreaks, options.maxWidth, textWidth);
|
|
20637
20637
|
var encodedLines = new Array(lines.length);
|
|
20638
20638
|
for (var idx = 0, len = lines.length;idx < len; idx++) {
|
|
20639
20639
|
encodedLines[idx] = newFont.encodeText(lines[idx]);
|
|
@@ -21063,9 +21063,9 @@ var require_PDFButton = __commonJS((exports) => {
|
|
|
21063
21063
|
this.acroField.setFontSize(fontSize);
|
|
21064
21064
|
this.markAsDirty();
|
|
21065
21065
|
};
|
|
21066
|
-
PDFButton2.prototype.addToPage = function(
|
|
21066
|
+
PDFButton2.prototype.addToPage = function(text3, page, options) {
|
|
21067
21067
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
21068
|
-
utils_1.assertOrUndefined(
|
|
21068
|
+
utils_1.assertOrUndefined(text3, "text", ["string"]);
|
|
21069
21069
|
utils_1.assertOrUndefined(page, "page", [[PDFPage_1.default, "PDFPage"]]);
|
|
21070
21070
|
PDFField_1.assertFieldAppearanceOptions(options);
|
|
21071
21071
|
var widget = this.createWidget({
|
|
@@ -21078,7 +21078,7 @@ var require_PDFButton = __commonJS((exports) => {
|
|
|
21078
21078
|
borderColor: options === null || options === undefined ? undefined : options.borderColor,
|
|
21079
21079
|
borderWidth: (_j = options === null || options === undefined ? undefined : options.borderWidth) !== null && _j !== undefined ? _j : 0,
|
|
21080
21080
|
rotate: (_k = options === null || options === undefined ? undefined : options.rotate) !== null && _k !== undefined ? _k : rotations_1.degrees(0),
|
|
21081
|
-
caption:
|
|
21081
|
+
caption: text3,
|
|
21082
21082
|
hidden: options === null || options === undefined ? undefined : options.hidden,
|
|
21083
21083
|
page: page.ref
|
|
21084
21084
|
});
|
|
@@ -21641,21 +21641,10 @@ function validatePublication(value) {
|
|
|
21641
21641
|
recipients: [...new Set([...extra, ...questions.flatMap((entry) => [entry.to, ...entry.allowedResponders])])]
|
|
21642
21642
|
};
|
|
21643
21643
|
}
|
|
21644
|
-
function oddington(value) {
|
|
21645
|
-
const source = object(value, "Oddington assignment");
|
|
21646
|
-
keys(source, ["reason"], "Oddington assignment");
|
|
21647
|
-
return { type: "oddington", reason: text(source.reason, "Oddington reason") };
|
|
21648
|
-
}
|
|
21649
21644
|
function continueAsk(value) {
|
|
21650
21645
|
const source = object(value, "continueAsk");
|
|
21651
|
-
keys(source, [
|
|
21652
|
-
|
|
21653
|
-
return { type: "continue" };
|
|
21654
|
-
const assignment = object(source.assignTo, "assignment");
|
|
21655
|
-
keys(assignment, ["type", "reason"], "assignment");
|
|
21656
|
-
if (assignment.type !== "oddington")
|
|
21657
|
-
fail("Only Oddington assignment is supported");
|
|
21658
|
-
return { type: "continue", assignTo: oddington({ reason: assignment.reason }) };
|
|
21646
|
+
keys(source, [], "continueAsk");
|
|
21647
|
+
return { type: "continue" };
|
|
21659
21648
|
}
|
|
21660
21649
|
function resolution(value) {
|
|
21661
21650
|
const source = object(value, "resolution");
|
|
@@ -21798,6 +21787,340 @@ function validateRoutineRecordWrite(value) {
|
|
|
21798
21787
|
function validCreatePath(value) {
|
|
21799
21788
|
return value === value.trim() && value.endsWith(".md") && !value.startsWith("/") && value.split("/").every((segment) => !!segment && ![".", ".."].includes(segment) && /^[a-zA-Z0-9_.-]+$/.test(segment));
|
|
21800
21789
|
}
|
|
21790
|
+
// ../../shared/connections.ts
|
|
21791
|
+
function validGoogleScopes(value) {
|
|
21792
|
+
return Array.isArray(value) && value.length > 0 && value.length <= 32 && value.every((scope) => typeof scope === "string" && scope.length <= 256 && /^(https:\/\/www\.googleapis\.com\/auth\/[A-Za-z0-9._-]+|https:\/\/mail\.google\.com\/|openid|email|profile)$/.test(scope)) && new Set(value).size === value.length;
|
|
21793
|
+
}
|
|
21794
|
+
|
|
21795
|
+
// ../../shared/connection-lease.ts
|
|
21796
|
+
var ROUTINE_CONNECTION_CREDENTIALS_ENV = "ODDINGTON_ROUTINE_CONNECTION_CREDENTIALS";
|
|
21797
|
+
var connectionUuid = (v) => typeof v === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(v);
|
|
21798
|
+
function parseConnectionLease(raw, now = Date.now()) {
|
|
21799
|
+
const v = raw;
|
|
21800
|
+
if (!v || typeof v !== "object" || Array.isArray(v) || !connectionUuid(v.connectionId) || !connectionUuid(v.runId) || typeof v.name !== "string" || !/^[a-z0-9][a-z0-9-]{0,62}$/.test(v.name) || typeof v.accessToken !== "string" || !/^[A-Za-z0-9._~+/-]{1,8192}={0,2}$/.test(v.accessToken))
|
|
21801
|
+
throw new Error("Invalid connection credential");
|
|
21802
|
+
if (v.provider === "gmail") {
|
|
21803
|
+
if (Object.keys(v).sort().join(",") !== "accessToken,accountEmail,connectionId,expiresAt,name,provider,runId,scopes" || typeof v.accountEmail !== "string" || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v.accountEmail) || !validGoogleScopes(v.scopes) || typeof v.expiresAt !== "string" || !Number.isFinite(Date.parse(v.expiresAt)) || Date.parse(v.expiresAt) <= now + 60000 || Date.parse(v.expiresAt) > now + 3600000)
|
|
21804
|
+
throw new Error("Invalid connection credential");
|
|
21805
|
+
return v;
|
|
21806
|
+
}
|
|
21807
|
+
if (v.provider === "airtable" && Object.keys(v).sort().join(",") === "accessToken,baseId,connectionId,name,provider,runExpiresAt,runId" && typeof v.baseId === "string" && /^app[A-Za-z0-9]+$/.test(v.baseId) && typeof v.runExpiresAt === "string" && Number.isFinite(Date.parse(v.runExpiresAt)) && Date.parse(v.runExpiresAt) > now + 60000 && Date.parse(v.runExpiresAt) <= now + 15 * 60000)
|
|
21808
|
+
return v;
|
|
21809
|
+
throw new Error("Invalid connection credential");
|
|
21810
|
+
}
|
|
21811
|
+
|
|
21812
|
+
// ../../shared/airtable-contract.ts
|
|
21813
|
+
class AirtableOperationError extends Error {
|
|
21814
|
+
effect;
|
|
21815
|
+
receipts;
|
|
21816
|
+
constructor(message, effect = "unapplied", receipts = []) {
|
|
21817
|
+
super(message);
|
|
21818
|
+
this.effect = effect;
|
|
21819
|
+
this.receipts = receipts;
|
|
21820
|
+
this.name = "AirtableOperationError";
|
|
21821
|
+
}
|
|
21822
|
+
}
|
|
21823
|
+
|
|
21824
|
+
// ../../shared/airtable-client.ts
|
|
21825
|
+
var recordId = (v) => typeof v === "string" && /^rec[A-Za-z0-9]+$/.test(v);
|
|
21826
|
+
var tableId = (v) => typeof v === "string" && /^tbl[A-Za-z0-9]+$/.test(v);
|
|
21827
|
+
function fail2(message) {
|
|
21828
|
+
throw new AirtableOperationError(message);
|
|
21829
|
+
}
|
|
21830
|
+
function object2(v) {
|
|
21831
|
+
if (!v || typeof v !== "object" || Array.isArray(v) || ![null, Object.prototype].includes(Object.getPrototypeOf(v)))
|
|
21832
|
+
fail2("Invalid Airtable data");
|
|
21833
|
+
return v;
|
|
21834
|
+
}
|
|
21835
|
+
function keys2(v, allowed, required = allowed) {
|
|
21836
|
+
if (Object.keys(v).some((k) => !allowed.includes(k)) || required.some((k) => !Object.hasOwn(v, k)))
|
|
21837
|
+
fail2("Invalid Airtable input");
|
|
21838
|
+
}
|
|
21839
|
+
function text2(v) {
|
|
21840
|
+
return typeof v === "string" && v.length > 0 && v.length <= 1024;
|
|
21841
|
+
}
|
|
21842
|
+
function fields2(v, nonempty = false) {
|
|
21843
|
+
const result = object2(v);
|
|
21844
|
+
if (nonempty && !Object.keys(result).length || Object.keys(result).some((k) => !text2(k)))
|
|
21845
|
+
fail2("Invalid Airtable fields");
|
|
21846
|
+
try {
|
|
21847
|
+
return serializable(result);
|
|
21848
|
+
} catch {
|
|
21849
|
+
return fail2("Invalid Airtable fields");
|
|
21850
|
+
}
|
|
21851
|
+
}
|
|
21852
|
+
function record(v) {
|
|
21853
|
+
const r = object2(v);
|
|
21854
|
+
if (!recordId(r.id) || r.createdTime !== undefined && (typeof r.createdTime !== "string" || !Number.isFinite(Date.parse(r.createdTime))))
|
|
21855
|
+
fail2("Malformed Airtable record");
|
|
21856
|
+
return { id: r.id, ...r.createdTime === undefined ? {} : { createdTime: r.createdTime }, fields: fields2(r.fields) };
|
|
21857
|
+
}
|
|
21858
|
+
function equal(a, b) {
|
|
21859
|
+
if (a === b)
|
|
21860
|
+
return true;
|
|
21861
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object" || Array.isArray(a) !== Array.isArray(b))
|
|
21862
|
+
return false;
|
|
21863
|
+
const left = Object.keys(a), right = Object.keys(b);
|
|
21864
|
+
return left.length === right.length && left.every((k) => Object.hasOwn(b, k) && equal(a[k], b[k]));
|
|
21865
|
+
}
|
|
21866
|
+
function createConnections(transport) {
|
|
21867
|
+
return { airtable(name) {
|
|
21868
|
+
if (typeof name !== "string" || !/^[a-z0-9][a-z0-9-]{0,62}$/.test(name))
|
|
21869
|
+
fail2("Invalid Airtable connection name");
|
|
21870
|
+
const call = (operation, input) => transport(name, operation, input);
|
|
21871
|
+
return {
|
|
21872
|
+
tables: { list: async () => await call("tables.list", {}) },
|
|
21873
|
+
records: {
|
|
21874
|
+
list: async (input) => await call("records.list", input),
|
|
21875
|
+
get: async (input) => await call("records.get", input),
|
|
21876
|
+
create: async (input) => await call("records.create", input),
|
|
21877
|
+
update: async (input) => await call("records.update", input),
|
|
21878
|
+
delete: async (input) => await call("records.delete", input)
|
|
21879
|
+
}
|
|
21880
|
+
};
|
|
21881
|
+
} };
|
|
21882
|
+
}
|
|
21883
|
+
async function executeAirtableOperation(authority, operation, raw, options = {}) {
|
|
21884
|
+
const { name, baseId, accessToken } = authority;
|
|
21885
|
+
if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(name) || !/^app[A-Za-z0-9]+$/.test(baseId) || !/^[A-Za-z0-9._~+/-]{1,8192}={0,2}$/.test(accessToken))
|
|
21886
|
+
fail2("Airtable connection unavailable");
|
|
21887
|
+
let input;
|
|
21888
|
+
try {
|
|
21889
|
+
input = object2(serializable(raw));
|
|
21890
|
+
} catch {
|
|
21891
|
+
return fail2("Invalid Airtable input");
|
|
21892
|
+
}
|
|
21893
|
+
const mutation = ["records.create", "records.update", "records.delete"].includes(operation);
|
|
21894
|
+
const receipt = (ids2) => ({
|
|
21895
|
+
provider: "airtable",
|
|
21896
|
+
connection: `airtable/${name}`,
|
|
21897
|
+
baseId,
|
|
21898
|
+
table: input.table,
|
|
21899
|
+
operation: operation.slice(8),
|
|
21900
|
+
records: ids2.map((id2) => ({ id: id2 }))
|
|
21901
|
+
});
|
|
21902
|
+
async function request(path2, init = {}, write = false) {
|
|
21903
|
+
let response;
|
|
21904
|
+
try {
|
|
21905
|
+
response = await (options.fetch ?? fetch)(`https://api.airtable.com/v0/${path2}`, {
|
|
21906
|
+
...init,
|
|
21907
|
+
headers: { authorization: `Bearer ${accessToken}`, "content-type": "application/json" },
|
|
21908
|
+
redirect: "manual",
|
|
21909
|
+
signal: options.signal ? AbortSignal.any([options.signal, AbortSignal.timeout(15000)]) : AbortSignal.timeout(15000)
|
|
21910
|
+
});
|
|
21911
|
+
} catch {
|
|
21912
|
+
throw new AirtableOperationError("Airtable request acknowledgment unavailable", write ? "uncertain" : "unapplied");
|
|
21913
|
+
}
|
|
21914
|
+
if (!response.ok) {
|
|
21915
|
+
await response.body?.cancel().catch(() => {});
|
|
21916
|
+
throw new AirtableOperationError("Airtable request rejected", write && (response.status >= 500 || response.status === 408 || response.status < 400) ? "uncertain" : "unapplied");
|
|
21917
|
+
}
|
|
21918
|
+
try {
|
|
21919
|
+
if (!response.headers.get("content-type")?.toLowerCase().includes("application/json"))
|
|
21920
|
+
throw new Error;
|
|
21921
|
+
const value = object2(await response.json());
|
|
21922
|
+
const safe = serializable(value);
|
|
21923
|
+
if (Object.hasOwn(value, "error") || JSON.stringify(safe).includes(accessToken))
|
|
21924
|
+
throw new Error;
|
|
21925
|
+
return value;
|
|
21926
|
+
} catch {
|
|
21927
|
+
throw new AirtableOperationError("Malformed Airtable acknowledgment", write ? "uncertain" : "unapplied");
|
|
21928
|
+
}
|
|
21929
|
+
}
|
|
21930
|
+
if (operation === "tables.list") {
|
|
21931
|
+
keys2(input, []);
|
|
21932
|
+
const tables = [], seen = new Set;
|
|
21933
|
+
let offset;
|
|
21934
|
+
do {
|
|
21935
|
+
const query2 = new URLSearchParams(offset ? { offset } : {});
|
|
21936
|
+
const page = await request(`meta/bases/${baseId}/tables?${query2}`);
|
|
21937
|
+
if (!Array.isArray(page.tables))
|
|
21938
|
+
fail2("Malformed Airtable tables");
|
|
21939
|
+
for (const value of page.tables) {
|
|
21940
|
+
const t = object2(value);
|
|
21941
|
+
if (!tableId(t.id) || !text2(t.name) || !text2(t.primaryFieldId) || !Array.isArray(t.fields) || tables.some((existing) => existing.id === t.id))
|
|
21942
|
+
fail2("Malformed Airtable table");
|
|
21943
|
+
const metadata = t.fields.map((value2) => {
|
|
21944
|
+
const f = object2(value2);
|
|
21945
|
+
if (typeof f.id !== "string" || !/^fld[A-Za-z0-9]+$/.test(f.id) || !text2(f.name) || !text2(f.type))
|
|
21946
|
+
fail2("Malformed Airtable field");
|
|
21947
|
+
return { id: f.id, name: f.name, type: f.type, ...f.options === undefined ? {} : { options: serializable(f.options) } };
|
|
21948
|
+
});
|
|
21949
|
+
if (!metadata.some((f) => f.id === t.primaryFieldId) || new Set(metadata.map((f) => f.id)).size !== metadata.length)
|
|
21950
|
+
fail2("Malformed Airtable fields");
|
|
21951
|
+
tables.push({ id: t.id, name: t.name, primaryFieldId: t.primaryFieldId, fields: metadata });
|
|
21952
|
+
}
|
|
21953
|
+
offset = nextOffset(page.offset, seen);
|
|
21954
|
+
} while (offset);
|
|
21955
|
+
return tables;
|
|
21956
|
+
}
|
|
21957
|
+
if (!text2(input.table) || input.table === "." || input.table === "..")
|
|
21958
|
+
fail2("Invalid Airtable table");
|
|
21959
|
+
if (mutation && !tableId(input.table))
|
|
21960
|
+
fail2("Airtable writes require a stable table ID");
|
|
21961
|
+
const path = `${baseId}/${encodeURIComponent(input.table)}`;
|
|
21962
|
+
if (operation === "records.get") {
|
|
21963
|
+
keys2(input, ["table", "id"]);
|
|
21964
|
+
if (!recordId(input.id))
|
|
21965
|
+
fail2("Invalid Airtable record ID");
|
|
21966
|
+
const result2 = record(await request(`${path}/${input.id}`));
|
|
21967
|
+
if (result2.id !== input.id)
|
|
21968
|
+
fail2("Malformed Airtable record");
|
|
21969
|
+
return result2;
|
|
21970
|
+
}
|
|
21971
|
+
if (operation === "records.list") {
|
|
21972
|
+
keys2(input, ["table", "fields"], ["table"]);
|
|
21973
|
+
if (input.fields !== undefined && (!Array.isArray(input.fields) || !input.fields.length || input.fields.some((f) => !text2(f)) || new Set(input.fields).size !== input.fields.length))
|
|
21974
|
+
fail2("Invalid Airtable field selection");
|
|
21975
|
+
const records2 = [], ids2 = new Set, seen = new Set;
|
|
21976
|
+
let offset;
|
|
21977
|
+
do {
|
|
21978
|
+
const query2 = new URLSearchParams;
|
|
21979
|
+
for (const field of input.fields ?? [])
|
|
21980
|
+
query2.append("fields[]", field);
|
|
21981
|
+
if (offset)
|
|
21982
|
+
query2.set("offset", offset);
|
|
21983
|
+
const page = await request(`${path}?${query2}`);
|
|
21984
|
+
if (!Array.isArray(page.records))
|
|
21985
|
+
fail2("Malformed Airtable records");
|
|
21986
|
+
for (const value of page.records) {
|
|
21987
|
+
const r = record(value);
|
|
21988
|
+
if (ids2.has(r.id))
|
|
21989
|
+
fail2("Malformed Airtable pagination");
|
|
21990
|
+
ids2.add(r.id);
|
|
21991
|
+
records2.push(r);
|
|
21992
|
+
}
|
|
21993
|
+
offset = nextOffset(page.offset, seen);
|
|
21994
|
+
} while (offset);
|
|
21995
|
+
return records2;
|
|
21996
|
+
}
|
|
21997
|
+
if (!mutation)
|
|
21998
|
+
fail2("Unsupported Airtable operation");
|
|
21999
|
+
keys2(input, ["table", "records"]);
|
|
22000
|
+
if (!Array.isArray(input.records) || !input.records.length || input.records.length > 10)
|
|
22001
|
+
fail2("Invalid Airtable batch");
|
|
22002
|
+
const kind = operation.slice(8), ids = new Set;
|
|
22003
|
+
const records = input.records.map((value) => {
|
|
22004
|
+
const r = object2(value);
|
|
22005
|
+
keys2(r, kind === "create" ? ["fields"] : kind === "update" ? ["id", "expected", "set"] : ["id", "expected"]);
|
|
22006
|
+
if (kind === "create")
|
|
22007
|
+
return { fields: fields2(r.fields, true) };
|
|
22008
|
+
if (!recordId(r.id) || ids.has(r.id))
|
|
22009
|
+
fail2("Invalid Airtable batch record ID");
|
|
22010
|
+
ids.add(r.id);
|
|
22011
|
+
const set = kind === "update" ? fields2(r.set, true) : undefined;
|
|
22012
|
+
if (set && Object.values(set).some((value2) => value2 === null))
|
|
22013
|
+
fail2("Airtable guard null cannot be an update value");
|
|
22014
|
+
return { id: r.id, expected: fields2(r.expected), ...set ? { set } : {} };
|
|
22015
|
+
});
|
|
22016
|
+
for (const r of records) {
|
|
22017
|
+
if (!("id" in r))
|
|
22018
|
+
continue;
|
|
22019
|
+
const current = record(await request(`${path}/${r.id}`));
|
|
22020
|
+
if (current.id !== r.id)
|
|
22021
|
+
fail2("Malformed Airtable record");
|
|
22022
|
+
for (const [key, value] of Object.entries(r.expected)) {
|
|
22023
|
+
if (value === null ? Object.hasOwn(current.fields, key) : !Object.hasOwn(current.fields, key) || !equal(current.fields[key], value))
|
|
22024
|
+
fail2("Airtable reviewed values are stale");
|
|
22025
|
+
}
|
|
22026
|
+
}
|
|
22027
|
+
await options.beforeMutation?.();
|
|
22028
|
+
const query = new URLSearchParams;
|
|
22029
|
+
if (kind === "delete")
|
|
22030
|
+
for (const id2 of ids)
|
|
22031
|
+
query.append("records[]", id2);
|
|
22032
|
+
const result = await request(`${path}${kind === "delete" ? `?${query}` : ""}`, {
|
|
22033
|
+
method: kind === "create" ? "POST" : kind === "update" ? "PATCH" : "DELETE",
|
|
22034
|
+
...kind === "delete" ? {} : { body: JSON.stringify({ records: records.map((r) => ("id" in r) ? { id: r.id, fields: r.set } : r) }) }
|
|
22035
|
+
}, true);
|
|
22036
|
+
const acknowledged = [], returned = [];
|
|
22037
|
+
try {
|
|
22038
|
+
if (!Array.isArray(result.records))
|
|
22039
|
+
throw new Error;
|
|
22040
|
+
for (const value of result.records) {
|
|
22041
|
+
const r = object2(value);
|
|
22042
|
+
if (!recordId(r.id) || acknowledged.includes(r.id) || kind !== "create" && !ids.has(r.id) || kind === "delete" && r.deleted !== true)
|
|
22043
|
+
throw new Error;
|
|
22044
|
+
acknowledged.push(r.id);
|
|
22045
|
+
if (kind !== "delete")
|
|
22046
|
+
returned.push(record(r));
|
|
22047
|
+
}
|
|
22048
|
+
if (acknowledged.length !== records.length)
|
|
22049
|
+
throw new Error;
|
|
22050
|
+
} catch {
|
|
22051
|
+
throw new AirtableOperationError("Incomplete Airtable mutation acknowledgment", acknowledged.length ? "partial" : "uncertain", acknowledged.length ? [receipt(acknowledged)] : []);
|
|
22052
|
+
}
|
|
22053
|
+
return { receipt: receipt(acknowledged), ...kind === "delete" ? {} : { records: returned } };
|
|
22054
|
+
}
|
|
22055
|
+
function nextOffset(value, seen) {
|
|
22056
|
+
if (value === undefined)
|
|
22057
|
+
return;
|
|
22058
|
+
if (!text2(value) || seen.has(value))
|
|
22059
|
+
fail2("Malformed Airtable pagination");
|
|
22060
|
+
seen.add(value);
|
|
22061
|
+
return value;
|
|
22062
|
+
}
|
|
22063
|
+
|
|
22064
|
+
// ../../shared/airtable-transport.ts
|
|
22065
|
+
var MANAGED_CONNECTION_CAPABILITY_ENV = "ODDINGTON_MANAGED_CONNECTION_CAPABILITY";
|
|
22066
|
+
function managedConnections(capability) {
|
|
22067
|
+
const endpoint = new URL(capability.endpoint);
|
|
22068
|
+
if (endpoint.protocol !== "http:" || endpoint.hostname !== "127.0.0.1" || !endpoint.port || endpoint.pathname !== "/" || endpoint.search || endpoint.hash || endpoint.username || endpoint.password || !/^[0-9a-f-]{36}$/.test(capability.token))
|
|
22069
|
+
throw new AirtableOperationError("Airtable capability unavailable");
|
|
22070
|
+
const transport = async (name, operation, input) => {
|
|
22071
|
+
let safeInput;
|
|
22072
|
+
try {
|
|
22073
|
+
safeInput = serializable(input);
|
|
22074
|
+
} catch {
|
|
22075
|
+
safeInput = null;
|
|
22076
|
+
}
|
|
22077
|
+
try {
|
|
22078
|
+
const response = await fetch(new URL("airtable", endpoint), {
|
|
22079
|
+
method: "POST",
|
|
22080
|
+
redirect: "error",
|
|
22081
|
+
headers: { authorization: `Bearer ${capability.token}`, "content-type": "application/json" },
|
|
22082
|
+
body: JSON.stringify({ name, operation, input: safeInput }),
|
|
22083
|
+
signal: AbortSignal.timeout(125000)
|
|
22084
|
+
});
|
|
22085
|
+
const value = await response.json();
|
|
22086
|
+
if (!response.ok)
|
|
22087
|
+
throw new AirtableOperationError("Airtable operation failed; the execution retains its evidence", value.effect === "partial" || value.effect === "uncertain" ? value.effect : "unapplied", value.receipts ?? []);
|
|
22088
|
+
return value;
|
|
22089
|
+
} catch (error) {
|
|
22090
|
+
if (error instanceof AirtableOperationError)
|
|
22091
|
+
throw error;
|
|
22092
|
+
throw new AirtableOperationError("Airtable parent acknowledgment unavailable", ["records.create", "records.update", "records.delete"].includes(operation) ? "uncertain" : "unapplied");
|
|
22093
|
+
}
|
|
22094
|
+
};
|
|
22095
|
+
return createConnections(transport);
|
|
22096
|
+
}
|
|
22097
|
+
|
|
22098
|
+
// src/connections.ts
|
|
22099
|
+
var connections = createConnections(async (name, operation, input) => {
|
|
22100
|
+
try {
|
|
22101
|
+
const managed = process.env[MANAGED_CONNECTION_CAPABILITY_ENV];
|
|
22102
|
+
if (managed) {
|
|
22103
|
+
const client = managedConnections(JSON.parse(managed)).airtable(name);
|
|
22104
|
+
if (operation === "tables.list")
|
|
22105
|
+
return await client.tables.list();
|
|
22106
|
+
return await client.records[operation.slice(8)](input);
|
|
22107
|
+
}
|
|
22108
|
+
const raw = JSON.parse(process.env[ROUTINE_CONNECTION_CREDENTIALS_ENV] ?? "[]");
|
|
22109
|
+
if (!Array.isArray(raw))
|
|
22110
|
+
throw new Error;
|
|
22111
|
+
const leases = raw.map((value) => parseConnectionLease(value));
|
|
22112
|
+
if (leases.some((lease2) => lease2.provider !== "airtable") || new Set(leases.map((lease2) => lease2.name)).size !== leases.length)
|
|
22113
|
+
throw new Error;
|
|
22114
|
+
const lease = leases.find((lease2) => lease2.name === name);
|
|
22115
|
+
if (!lease || lease.provider !== "airtable")
|
|
22116
|
+
throw new Error;
|
|
22117
|
+
return await executeAirtableOperation(lease, operation, input);
|
|
22118
|
+
} catch (error) {
|
|
22119
|
+
if (error instanceof AirtableOperationError)
|
|
22120
|
+
throw error;
|
|
22121
|
+
throw new AirtableOperationError("Airtable connection unavailable");
|
|
22122
|
+
}
|
|
22123
|
+
});
|
|
21801
22124
|
// ../../shared/delimited-text.ts
|
|
21802
22125
|
function delimiterFor(value) {
|
|
21803
22126
|
const counts = new Map([
|
|
@@ -22198,11 +22521,12 @@ export {
|
|
|
22198
22521
|
recordsBlock,
|
|
22199
22522
|
recordBlock,
|
|
22200
22523
|
question,
|
|
22201
|
-
oddington,
|
|
22202
22524
|
fileBlock,
|
|
22203
22525
|
defineHandler,
|
|
22204
22526
|
continueAsk,
|
|
22527
|
+
connections,
|
|
22205
22528
|
asksBlock,
|
|
22206
22529
|
RoutineRecordWriteError,
|
|
22207
|
-
InboxContractError
|
|
22530
|
+
InboxContractError,
|
|
22531
|
+
AirtableOperationError
|
|
22208
22532
|
};
|