cdk-turso 0.0.2 → 0.0.4
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/.jsii +178 -4
- package/AGENTS.md +120 -18
- package/API.md +205 -0
- package/README.md +35 -0
- package/lib/handler/index.js +588 -24
- package/lib/handler-auth-token/index.d.ts +15 -0
- package/lib/handler-auth-token/index.js +708 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -2
- package/lib/turso-auth-token.d.ts +32 -0
- package/lib/turso-auth-token.js +66 -0
- package/lib/turso-database.d.ts +2 -0
- package/lib/turso-database.js +4 -2
- package/package.json +2 -1
package/lib/handler/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,8 +20,562 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
18
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
32
|
|
|
33
|
+
// node_modules/exponential-backoff/dist/options.js
|
|
34
|
+
var require_options = __commonJS({
|
|
35
|
+
"node_modules/exponential-backoff/dist/options.js"(exports2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var __assign = exports2 && exports2.__assign || function() {
|
|
38
|
+
__assign = Object.assign || function(t) {
|
|
39
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
+
s = arguments[i];
|
|
41
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
42
|
+
t[p] = s[p];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
};
|
|
46
|
+
return __assign.apply(this, arguments);
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
49
|
+
var defaultOptions = {
|
|
50
|
+
delayFirstAttempt: false,
|
|
51
|
+
jitter: "none",
|
|
52
|
+
maxDelay: Infinity,
|
|
53
|
+
numOfAttempts: 10,
|
|
54
|
+
retry: function() {
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
startingDelay: 100,
|
|
58
|
+
timeMultiple: 2
|
|
59
|
+
};
|
|
60
|
+
function getSanitizedOptions(options) {
|
|
61
|
+
var sanitized = __assign(__assign({}, defaultOptions), options);
|
|
62
|
+
if (sanitized.numOfAttempts < 1) {
|
|
63
|
+
sanitized.numOfAttempts = 1;
|
|
64
|
+
}
|
|
65
|
+
return sanitized;
|
|
66
|
+
}
|
|
67
|
+
exports2.getSanitizedOptions = getSanitizedOptions;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// node_modules/exponential-backoff/dist/jitter/full/full.jitter.js
|
|
72
|
+
var require_full_jitter = __commonJS({
|
|
73
|
+
"node_modules/exponential-backoff/dist/jitter/full/full.jitter.js"(exports2) {
|
|
74
|
+
"use strict";
|
|
75
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
76
|
+
function fullJitter(delay) {
|
|
77
|
+
var jitteredDelay = Math.random() * delay;
|
|
78
|
+
return Math.round(jitteredDelay);
|
|
79
|
+
}
|
|
80
|
+
exports2.fullJitter = fullJitter;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// node_modules/exponential-backoff/dist/jitter/no/no.jitter.js
|
|
85
|
+
var require_no_jitter = __commonJS({
|
|
86
|
+
"node_modules/exponential-backoff/dist/jitter/no/no.jitter.js"(exports2) {
|
|
87
|
+
"use strict";
|
|
88
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
89
|
+
function noJitter(delay) {
|
|
90
|
+
return delay;
|
|
91
|
+
}
|
|
92
|
+
exports2.noJitter = noJitter;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// node_modules/exponential-backoff/dist/jitter/jitter.factory.js
|
|
97
|
+
var require_jitter_factory = __commonJS({
|
|
98
|
+
"node_modules/exponential-backoff/dist/jitter/jitter.factory.js"(exports2) {
|
|
99
|
+
"use strict";
|
|
100
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
101
|
+
var full_jitter_1 = require_full_jitter();
|
|
102
|
+
var no_jitter_1 = require_no_jitter();
|
|
103
|
+
function JitterFactory(options) {
|
|
104
|
+
switch (options.jitter) {
|
|
105
|
+
case "full":
|
|
106
|
+
return full_jitter_1.fullJitter;
|
|
107
|
+
case "none":
|
|
108
|
+
default:
|
|
109
|
+
return no_jitter_1.noJitter;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports2.JitterFactory = JitterFactory;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// node_modules/exponential-backoff/dist/delay/delay.base.js
|
|
117
|
+
var require_delay_base = __commonJS({
|
|
118
|
+
"node_modules/exponential-backoff/dist/delay/delay.base.js"(exports2) {
|
|
119
|
+
"use strict";
|
|
120
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
121
|
+
var jitter_factory_1 = require_jitter_factory();
|
|
122
|
+
var Delay = (
|
|
123
|
+
/** @class */
|
|
124
|
+
(function() {
|
|
125
|
+
function Delay2(options) {
|
|
126
|
+
this.options = options;
|
|
127
|
+
this.attempt = 0;
|
|
128
|
+
}
|
|
129
|
+
Delay2.prototype.apply = function() {
|
|
130
|
+
var _this = this;
|
|
131
|
+
return new Promise(function(resolve) {
|
|
132
|
+
return setTimeout(resolve, _this.jitteredDelay);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
Delay2.prototype.setAttemptNumber = function(attempt) {
|
|
136
|
+
this.attempt = attempt;
|
|
137
|
+
};
|
|
138
|
+
Object.defineProperty(Delay2.prototype, "jitteredDelay", {
|
|
139
|
+
get: function() {
|
|
140
|
+
var jitter = jitter_factory_1.JitterFactory(this.options);
|
|
141
|
+
return jitter(this.delay);
|
|
142
|
+
},
|
|
143
|
+
enumerable: true,
|
|
144
|
+
configurable: true
|
|
145
|
+
});
|
|
146
|
+
Object.defineProperty(Delay2.prototype, "delay", {
|
|
147
|
+
get: function() {
|
|
148
|
+
var constant = this.options.startingDelay;
|
|
149
|
+
var base = this.options.timeMultiple;
|
|
150
|
+
var power = this.numOfDelayedAttempts;
|
|
151
|
+
var delay = constant * Math.pow(base, power);
|
|
152
|
+
return Math.min(delay, this.options.maxDelay);
|
|
153
|
+
},
|
|
154
|
+
enumerable: true,
|
|
155
|
+
configurable: true
|
|
156
|
+
});
|
|
157
|
+
Object.defineProperty(Delay2.prototype, "numOfDelayedAttempts", {
|
|
158
|
+
get: function() {
|
|
159
|
+
return this.attempt;
|
|
160
|
+
},
|
|
161
|
+
enumerable: true,
|
|
162
|
+
configurable: true
|
|
163
|
+
});
|
|
164
|
+
return Delay2;
|
|
165
|
+
})()
|
|
166
|
+
);
|
|
167
|
+
exports2.Delay = Delay;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// node_modules/exponential-backoff/dist/delay/skip-first/skip-first.delay.js
|
|
172
|
+
var require_skip_first_delay = __commonJS({
|
|
173
|
+
"node_modules/exponential-backoff/dist/delay/skip-first/skip-first.delay.js"(exports2) {
|
|
174
|
+
"use strict";
|
|
175
|
+
var __extends = exports2 && exports2.__extends || /* @__PURE__ */ (function() {
|
|
176
|
+
var extendStatics = function(d, b) {
|
|
177
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
178
|
+
d2.__proto__ = b2;
|
|
179
|
+
} || function(d2, b2) {
|
|
180
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
181
|
+
};
|
|
182
|
+
return extendStatics(d, b);
|
|
183
|
+
};
|
|
184
|
+
return function(d, b) {
|
|
185
|
+
extendStatics(d, b);
|
|
186
|
+
function __() {
|
|
187
|
+
this.constructor = d;
|
|
188
|
+
}
|
|
189
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
190
|
+
};
|
|
191
|
+
})();
|
|
192
|
+
var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
193
|
+
function adopt(value) {
|
|
194
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
195
|
+
resolve(value);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
199
|
+
function fulfilled(value) {
|
|
200
|
+
try {
|
|
201
|
+
step(generator.next(value));
|
|
202
|
+
} catch (e) {
|
|
203
|
+
reject(e);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function rejected(value) {
|
|
207
|
+
try {
|
|
208
|
+
step(generator["throw"](value));
|
|
209
|
+
} catch (e) {
|
|
210
|
+
reject(e);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function step(result) {
|
|
214
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
215
|
+
}
|
|
216
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
var __generator = exports2 && exports2.__generator || function(thisArg, body) {
|
|
220
|
+
var _ = { label: 0, sent: function() {
|
|
221
|
+
if (t[0] & 1) throw t[1];
|
|
222
|
+
return t[1];
|
|
223
|
+
}, trys: [], ops: [] }, f, y, t, g;
|
|
224
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
225
|
+
return this;
|
|
226
|
+
}), g;
|
|
227
|
+
function verb(n) {
|
|
228
|
+
return function(v) {
|
|
229
|
+
return step([n, v]);
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function step(op) {
|
|
233
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
234
|
+
while (_) try {
|
|
235
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
236
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
237
|
+
switch (op[0]) {
|
|
238
|
+
case 0:
|
|
239
|
+
case 1:
|
|
240
|
+
t = op;
|
|
241
|
+
break;
|
|
242
|
+
case 4:
|
|
243
|
+
_.label++;
|
|
244
|
+
return { value: op[1], done: false };
|
|
245
|
+
case 5:
|
|
246
|
+
_.label++;
|
|
247
|
+
y = op[1];
|
|
248
|
+
op = [0];
|
|
249
|
+
continue;
|
|
250
|
+
case 7:
|
|
251
|
+
op = _.ops.pop();
|
|
252
|
+
_.trys.pop();
|
|
253
|
+
continue;
|
|
254
|
+
default:
|
|
255
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
256
|
+
_ = 0;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
260
|
+
_.label = op[1];
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
264
|
+
_.label = t[1];
|
|
265
|
+
t = op;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
if (t && _.label < t[2]) {
|
|
269
|
+
_.label = t[2];
|
|
270
|
+
_.ops.push(op);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
if (t[2]) _.ops.pop();
|
|
274
|
+
_.trys.pop();
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
op = body.call(thisArg, _);
|
|
278
|
+
} catch (e) {
|
|
279
|
+
op = [6, e];
|
|
280
|
+
y = 0;
|
|
281
|
+
} finally {
|
|
282
|
+
f = t = 0;
|
|
283
|
+
}
|
|
284
|
+
if (op[0] & 5) throw op[1];
|
|
285
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
289
|
+
var delay_base_1 = require_delay_base();
|
|
290
|
+
var SkipFirstDelay = (
|
|
291
|
+
/** @class */
|
|
292
|
+
(function(_super) {
|
|
293
|
+
__extends(SkipFirstDelay2, _super);
|
|
294
|
+
function SkipFirstDelay2() {
|
|
295
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
296
|
+
}
|
|
297
|
+
SkipFirstDelay2.prototype.apply = function() {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
299
|
+
return __generator(this, function(_a) {
|
|
300
|
+
return [2, this.isFirstAttempt ? true : _super.prototype.apply.call(this)];
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
Object.defineProperty(SkipFirstDelay2.prototype, "isFirstAttempt", {
|
|
305
|
+
get: function() {
|
|
306
|
+
return this.attempt === 0;
|
|
307
|
+
},
|
|
308
|
+
enumerable: true,
|
|
309
|
+
configurable: true
|
|
310
|
+
});
|
|
311
|
+
Object.defineProperty(SkipFirstDelay2.prototype, "numOfDelayedAttempts", {
|
|
312
|
+
get: function() {
|
|
313
|
+
return this.attempt - 1;
|
|
314
|
+
},
|
|
315
|
+
enumerable: true,
|
|
316
|
+
configurable: true
|
|
317
|
+
});
|
|
318
|
+
return SkipFirstDelay2;
|
|
319
|
+
})(delay_base_1.Delay)
|
|
320
|
+
);
|
|
321
|
+
exports2.SkipFirstDelay = SkipFirstDelay;
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// node_modules/exponential-backoff/dist/delay/always/always.delay.js
|
|
326
|
+
var require_always_delay = __commonJS({
|
|
327
|
+
"node_modules/exponential-backoff/dist/delay/always/always.delay.js"(exports2) {
|
|
328
|
+
"use strict";
|
|
329
|
+
var __extends = exports2 && exports2.__extends || /* @__PURE__ */ (function() {
|
|
330
|
+
var extendStatics = function(d, b) {
|
|
331
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
332
|
+
d2.__proto__ = b2;
|
|
333
|
+
} || function(d2, b2) {
|
|
334
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
335
|
+
};
|
|
336
|
+
return extendStatics(d, b);
|
|
337
|
+
};
|
|
338
|
+
return function(d, b) {
|
|
339
|
+
extendStatics(d, b);
|
|
340
|
+
function __() {
|
|
341
|
+
this.constructor = d;
|
|
342
|
+
}
|
|
343
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
344
|
+
};
|
|
345
|
+
})();
|
|
346
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
347
|
+
var delay_base_1 = require_delay_base();
|
|
348
|
+
var AlwaysDelay = (
|
|
349
|
+
/** @class */
|
|
350
|
+
(function(_super) {
|
|
351
|
+
__extends(AlwaysDelay2, _super);
|
|
352
|
+
function AlwaysDelay2() {
|
|
353
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
354
|
+
}
|
|
355
|
+
return AlwaysDelay2;
|
|
356
|
+
})(delay_base_1.Delay)
|
|
357
|
+
);
|
|
358
|
+
exports2.AlwaysDelay = AlwaysDelay;
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// node_modules/exponential-backoff/dist/delay/delay.factory.js
|
|
363
|
+
var require_delay_factory = __commonJS({
|
|
364
|
+
"node_modules/exponential-backoff/dist/delay/delay.factory.js"(exports2) {
|
|
365
|
+
"use strict";
|
|
366
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
367
|
+
var skip_first_delay_1 = require_skip_first_delay();
|
|
368
|
+
var always_delay_1 = require_always_delay();
|
|
369
|
+
function DelayFactory(options, attempt) {
|
|
370
|
+
var delay = initDelayClass(options);
|
|
371
|
+
delay.setAttemptNumber(attempt);
|
|
372
|
+
return delay;
|
|
373
|
+
}
|
|
374
|
+
exports2.DelayFactory = DelayFactory;
|
|
375
|
+
function initDelayClass(options) {
|
|
376
|
+
if (!options.delayFirstAttempt) {
|
|
377
|
+
return new skip_first_delay_1.SkipFirstDelay(options);
|
|
378
|
+
}
|
|
379
|
+
return new always_delay_1.AlwaysDelay(options);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// node_modules/exponential-backoff/dist/backoff.js
|
|
385
|
+
var require_backoff = __commonJS({
|
|
386
|
+
"node_modules/exponential-backoff/dist/backoff.js"(exports2) {
|
|
387
|
+
"use strict";
|
|
388
|
+
var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
389
|
+
function adopt(value) {
|
|
390
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
391
|
+
resolve(value);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
395
|
+
function fulfilled(value) {
|
|
396
|
+
try {
|
|
397
|
+
step(generator.next(value));
|
|
398
|
+
} catch (e) {
|
|
399
|
+
reject(e);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function rejected(value) {
|
|
403
|
+
try {
|
|
404
|
+
step(generator["throw"](value));
|
|
405
|
+
} catch (e) {
|
|
406
|
+
reject(e);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
function step(result) {
|
|
410
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
411
|
+
}
|
|
412
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
var __generator = exports2 && exports2.__generator || function(thisArg, body) {
|
|
416
|
+
var _ = { label: 0, sent: function() {
|
|
417
|
+
if (t[0] & 1) throw t[1];
|
|
418
|
+
return t[1];
|
|
419
|
+
}, trys: [], ops: [] }, f, y, t, g;
|
|
420
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
421
|
+
return this;
|
|
422
|
+
}), g;
|
|
423
|
+
function verb(n) {
|
|
424
|
+
return function(v) {
|
|
425
|
+
return step([n, v]);
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function step(op) {
|
|
429
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
430
|
+
while (_) try {
|
|
431
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
432
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
433
|
+
switch (op[0]) {
|
|
434
|
+
case 0:
|
|
435
|
+
case 1:
|
|
436
|
+
t = op;
|
|
437
|
+
break;
|
|
438
|
+
case 4:
|
|
439
|
+
_.label++;
|
|
440
|
+
return { value: op[1], done: false };
|
|
441
|
+
case 5:
|
|
442
|
+
_.label++;
|
|
443
|
+
y = op[1];
|
|
444
|
+
op = [0];
|
|
445
|
+
continue;
|
|
446
|
+
case 7:
|
|
447
|
+
op = _.ops.pop();
|
|
448
|
+
_.trys.pop();
|
|
449
|
+
continue;
|
|
450
|
+
default:
|
|
451
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
452
|
+
_ = 0;
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
456
|
+
_.label = op[1];
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
460
|
+
_.label = t[1];
|
|
461
|
+
t = op;
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
if (t && _.label < t[2]) {
|
|
465
|
+
_.label = t[2];
|
|
466
|
+
_.ops.push(op);
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
if (t[2]) _.ops.pop();
|
|
470
|
+
_.trys.pop();
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
op = body.call(thisArg, _);
|
|
474
|
+
} catch (e) {
|
|
475
|
+
op = [6, e];
|
|
476
|
+
y = 0;
|
|
477
|
+
} finally {
|
|
478
|
+
f = t = 0;
|
|
479
|
+
}
|
|
480
|
+
if (op[0] & 5) throw op[1];
|
|
481
|
+
return { value: op[0] ? op[1] : void 0, done: true };
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
485
|
+
var options_1 = require_options();
|
|
486
|
+
var delay_factory_1 = require_delay_factory();
|
|
487
|
+
function backOff2(request, options) {
|
|
488
|
+
if (options === void 0) {
|
|
489
|
+
options = {};
|
|
490
|
+
}
|
|
491
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
492
|
+
var sanitizedOptions, backOff3;
|
|
493
|
+
return __generator(this, function(_a) {
|
|
494
|
+
switch (_a.label) {
|
|
495
|
+
case 0:
|
|
496
|
+
sanitizedOptions = options_1.getSanitizedOptions(options);
|
|
497
|
+
backOff3 = new BackOff(request, sanitizedOptions);
|
|
498
|
+
return [4, backOff3.execute()];
|
|
499
|
+
case 1:
|
|
500
|
+
return [2, _a.sent()];
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
exports2.backOff = backOff2;
|
|
506
|
+
var BackOff = (
|
|
507
|
+
/** @class */
|
|
508
|
+
(function() {
|
|
509
|
+
function BackOff2(request, options) {
|
|
510
|
+
this.request = request;
|
|
511
|
+
this.options = options;
|
|
512
|
+
this.attemptNumber = 0;
|
|
513
|
+
}
|
|
514
|
+
BackOff2.prototype.execute = function() {
|
|
515
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
516
|
+
var e_1, shouldRetry;
|
|
517
|
+
return __generator(this, function(_a) {
|
|
518
|
+
switch (_a.label) {
|
|
519
|
+
case 0:
|
|
520
|
+
if (!!this.attemptLimitReached) return [3, 7];
|
|
521
|
+
_a.label = 1;
|
|
522
|
+
case 1:
|
|
523
|
+
_a.trys.push([1, 4, , 6]);
|
|
524
|
+
return [4, this.applyDelay()];
|
|
525
|
+
case 2:
|
|
526
|
+
_a.sent();
|
|
527
|
+
return [4, this.request()];
|
|
528
|
+
case 3:
|
|
529
|
+
return [2, _a.sent()];
|
|
530
|
+
case 4:
|
|
531
|
+
e_1 = _a.sent();
|
|
532
|
+
this.attemptNumber++;
|
|
533
|
+
return [4, this.options.retry(e_1, this.attemptNumber)];
|
|
534
|
+
case 5:
|
|
535
|
+
shouldRetry = _a.sent();
|
|
536
|
+
if (!shouldRetry || this.attemptLimitReached) {
|
|
537
|
+
throw e_1;
|
|
538
|
+
}
|
|
539
|
+
return [3, 6];
|
|
540
|
+
case 6:
|
|
541
|
+
return [3, 0];
|
|
542
|
+
case 7:
|
|
543
|
+
throw new Error("Something went wrong.");
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
};
|
|
548
|
+
Object.defineProperty(BackOff2.prototype, "attemptLimitReached", {
|
|
549
|
+
get: function() {
|
|
550
|
+
return this.attemptNumber >= this.options.numOfAttempts;
|
|
551
|
+
},
|
|
552
|
+
enumerable: true,
|
|
553
|
+
configurable: true
|
|
554
|
+
});
|
|
555
|
+
BackOff2.prototype.applyDelay = function() {
|
|
556
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
557
|
+
var delay;
|
|
558
|
+
return __generator(this, function(_a) {
|
|
559
|
+
switch (_a.label) {
|
|
560
|
+
case 0:
|
|
561
|
+
delay = delay_factory_1.DelayFactory(this.options, this.attemptNumber);
|
|
562
|
+
return [4, delay.apply()];
|
|
563
|
+
case 1:
|
|
564
|
+
_a.sent();
|
|
565
|
+
return [
|
|
566
|
+
2
|
|
567
|
+
/*return*/
|
|
568
|
+
];
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
};
|
|
573
|
+
return BackOff2;
|
|
574
|
+
})()
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
|
|
20
579
|
// src/handler/index.ts
|
|
21
580
|
var index_exports = {};
|
|
22
581
|
__export(index_exports, {
|
|
@@ -24,7 +583,24 @@ __export(index_exports, {
|
|
|
24
583
|
});
|
|
25
584
|
module.exports = __toCommonJS(index_exports);
|
|
26
585
|
var import_client_ssm = require("@aws-sdk/client-ssm");
|
|
586
|
+
var import_exponential_backoff = __toESM(require_backoff());
|
|
27
587
|
var ssmClient = new import_client_ssm.SSMClient({});
|
|
588
|
+
var retryOptions = {
|
|
589
|
+
startingDelay: 5e3,
|
|
590
|
+
timeMultiple: 3,
|
|
591
|
+
numOfAttempts: 4,
|
|
592
|
+
jitter: "none"
|
|
593
|
+
};
|
|
594
|
+
async function fetchWithRetry(url, options, errorMessage, allow404) {
|
|
595
|
+
return (0, import_exponential_backoff.backOff)(async () => {
|
|
596
|
+
const response = await fetch(url, options);
|
|
597
|
+
if (!response.ok && !(allow404 && response.status === 404)) {
|
|
598
|
+
const errorText = await response.text();
|
|
599
|
+
throw new Error(`${errorMessage}: ${response.status} ${errorText}`);
|
|
600
|
+
}
|
|
601
|
+
return response;
|
|
602
|
+
}, retryOptions);
|
|
603
|
+
}
|
|
28
604
|
async function getApiToken(parameterName) {
|
|
29
605
|
const command = new import_client_ssm.GetParameterCommand({
|
|
30
606
|
Name: parameterName,
|
|
@@ -67,7 +643,7 @@ async function handler(event) {
|
|
|
67
643
|
if (ResourceProperties.Encryption) {
|
|
68
644
|
body.encryption = ResourceProperties.Encryption;
|
|
69
645
|
}
|
|
70
|
-
const response = await
|
|
646
|
+
const response = await fetchWithRetry(
|
|
71
647
|
`${baseUrl}/organizations/${orgSlug}/databases`,
|
|
72
648
|
{
|
|
73
649
|
method: "POST",
|
|
@@ -76,14 +652,10 @@ async function handler(event) {
|
|
|
76
652
|
"Content-Type": "application/json"
|
|
77
653
|
},
|
|
78
654
|
body: JSON.stringify(body)
|
|
79
|
-
}
|
|
655
|
+
},
|
|
656
|
+
"Failed to create database",
|
|
657
|
+
false
|
|
80
658
|
);
|
|
81
|
-
if (!response.ok) {
|
|
82
|
-
const errorText = await response.text();
|
|
83
|
-
throw new Error(
|
|
84
|
-
`Failed to create database: ${response.status} ${errorText}`
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
659
|
const data = await response.json();
|
|
88
660
|
return {
|
|
89
661
|
PhysicalResourceId: dbName,
|
|
@@ -102,7 +674,7 @@ async function handler(event) {
|
|
|
102
674
|
name: newDbName,
|
|
103
675
|
group: ResourceProperties.Group
|
|
104
676
|
};
|
|
105
|
-
const response = await
|
|
677
|
+
const response = await fetchWithRetry(
|
|
106
678
|
`${baseUrl}/organizations/${orgSlug}/databases`,
|
|
107
679
|
{
|
|
108
680
|
method: "POST",
|
|
@@ -111,14 +683,10 @@ async function handler(event) {
|
|
|
111
683
|
"Content-Type": "application/json"
|
|
112
684
|
},
|
|
113
685
|
body: JSON.stringify(body)
|
|
114
|
-
}
|
|
686
|
+
},
|
|
687
|
+
"Failed to create database",
|
|
688
|
+
false
|
|
115
689
|
);
|
|
116
|
-
if (!response.ok) {
|
|
117
|
-
const errorText = await response.text();
|
|
118
|
-
throw new Error(
|
|
119
|
-
`Failed to create database: ${response.status} ${errorText}`
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
690
|
const data = await response.json();
|
|
123
691
|
return {
|
|
124
692
|
PhysicalResourceId: newDbName,
|
|
@@ -141,21 +709,17 @@ async function handler(event) {
|
|
|
141
709
|
return { PhysicalResourceId };
|
|
142
710
|
}
|
|
143
711
|
const dbNameToDelete = encodeURIComponent(PhysicalResourceId);
|
|
144
|
-
|
|
712
|
+
await fetchWithRetry(
|
|
145
713
|
`${baseUrl}/organizations/${orgSlug}/databases/${dbNameToDelete}`,
|
|
146
714
|
{
|
|
147
715
|
method: "DELETE",
|
|
148
716
|
headers: {
|
|
149
717
|
Authorization: `Bearer ${apiToken}`
|
|
150
718
|
}
|
|
151
|
-
}
|
|
719
|
+
},
|
|
720
|
+
"Failed to delete database",
|
|
721
|
+
true
|
|
152
722
|
);
|
|
153
|
-
if (!response.ok && response.status !== 404) {
|
|
154
|
-
const errorText = await response.text();
|
|
155
|
-
throw new Error(
|
|
156
|
-
`Failed to delete database: ${response.status} ${errorText}`
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
723
|
return { PhysicalResourceId };
|
|
160
724
|
}
|
|
161
725
|
throw new Error(`Unknown request type: ${RequestType}`);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface CloudFormationCustomResourceEvent {
|
|
2
|
+
RequestType: "Create" | "Update" | "Delete";
|
|
3
|
+
PhysicalResourceId?: string;
|
|
4
|
+
ResourceProperties: {
|
|
5
|
+
ServiceToken: string;
|
|
6
|
+
DatabaseName: string;
|
|
7
|
+
OrganizationSlug: string;
|
|
8
|
+
ParameterName: string;
|
|
9
|
+
Expiration?: string;
|
|
10
|
+
Authorization?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function handler(event: CloudFormationCustomResourceEvent): Promise<{
|
|
14
|
+
PhysicalResourceId: string;
|
|
15
|
+
}>;
|