@supertokens-plugins/rownd-nodejs 0.2.0 → 0.2.1
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.d.mts +136 -0
- package/dist/index.d.ts +136 -0
- package/dist/index.js +1109 -0
- package/dist/index.mjs +1095 -0
- package/package.json +1 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1095 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
14
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
|
|
33
|
+
// ../../node_modules/supertokens-js-override/lib/build/getProxyObject.js
|
|
34
|
+
var require_getProxyObject = __commonJS({
|
|
35
|
+
"../../node_modules/supertokens-js-override/lib/build/getProxyObject.js"(exports) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var __assign = exports && exports.__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(exports, "__esModule", { value: true });
|
|
49
|
+
exports.getProxyObject = void 0;
|
|
50
|
+
function getProxyObject(orig) {
|
|
51
|
+
var ret = __assign(__assign({}, orig), { _call: function(_, __) {
|
|
52
|
+
throw new Error("This function should only be called through the recipe object");
|
|
53
|
+
} });
|
|
54
|
+
var keys = Object.keys(ret);
|
|
55
|
+
var _loop_1 = function(k2) {
|
|
56
|
+
if (k2 !== "_call") {
|
|
57
|
+
ret[k2] = function() {
|
|
58
|
+
var args = [];
|
|
59
|
+
for (var _i2 = 0; _i2 < arguments.length; _i2++) {
|
|
60
|
+
args[_i2] = arguments[_i2];
|
|
61
|
+
}
|
|
62
|
+
return this._call(k2, args);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
67
|
+
var k = keys_1[_i];
|
|
68
|
+
_loop_1(k);
|
|
69
|
+
}
|
|
70
|
+
return ret;
|
|
71
|
+
}
|
|
72
|
+
exports.getProxyObject = getProxyObject;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ../../node_modules/supertokens-js-override/lib/build/index.js
|
|
77
|
+
var require_build = __commonJS({
|
|
78
|
+
"../../node_modules/supertokens-js-override/lib/build/index.js"(exports) {
|
|
79
|
+
"use strict";
|
|
80
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
81
|
+
exports.OverrideableBuilder = void 0;
|
|
82
|
+
var getProxyObject_1 = require_getProxyObject();
|
|
83
|
+
var OverrideableBuilder2 = (
|
|
84
|
+
/** @class */
|
|
85
|
+
(function() {
|
|
86
|
+
function OverrideableBuilder3(originalImplementation) {
|
|
87
|
+
this.layers = [originalImplementation];
|
|
88
|
+
this.proxies = [];
|
|
89
|
+
}
|
|
90
|
+
OverrideableBuilder3.prototype.override = function(overrideFunc) {
|
|
91
|
+
var proxy = (0, getProxyObject_1.getProxyObject)(this.layers[0]);
|
|
92
|
+
var layer = overrideFunc(proxy, this);
|
|
93
|
+
for (var _i = 0, _a = Object.keys(this.layers[0]); _i < _a.length; _i++) {
|
|
94
|
+
var key = _a[_i];
|
|
95
|
+
if (layer[key] === proxy[key] || key === "_call") {
|
|
96
|
+
delete layer[key];
|
|
97
|
+
} else if (layer[key] === void 0) {
|
|
98
|
+
layer[key] = null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
this.layers.push(layer);
|
|
102
|
+
this.proxies.push(proxy);
|
|
103
|
+
return this;
|
|
104
|
+
};
|
|
105
|
+
OverrideableBuilder3.prototype.build = function() {
|
|
106
|
+
var _this = this;
|
|
107
|
+
if (this.result) {
|
|
108
|
+
return this.result;
|
|
109
|
+
}
|
|
110
|
+
this.result = {};
|
|
111
|
+
for (var _i = 0, _a = this.layers; _i < _a.length; _i++) {
|
|
112
|
+
var layer = _a[_i];
|
|
113
|
+
for (var _b = 0, _c = Object.keys(layer); _b < _c.length; _b++) {
|
|
114
|
+
var key = _c[_b];
|
|
115
|
+
var override = layer[key];
|
|
116
|
+
if (override !== void 0) {
|
|
117
|
+
if (override === null) {
|
|
118
|
+
this.result[key] = void 0;
|
|
119
|
+
} else if (typeof override === "function") {
|
|
120
|
+
this.result[key] = override.bind(this.result);
|
|
121
|
+
} else {
|
|
122
|
+
this.result[key] = override;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
var _loop_1 = function(proxyInd2) {
|
|
128
|
+
var proxy = this_1.proxies[proxyInd2];
|
|
129
|
+
proxy._call = function(fname, args) {
|
|
130
|
+
for (var i = proxyInd2; i >= 0; --i) {
|
|
131
|
+
var func = _this.layers[i][fname];
|
|
132
|
+
if (func !== void 0 && func !== null) {
|
|
133
|
+
return func.bind(_this.result).apply(void 0, args);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
var this_1 = this;
|
|
139
|
+
for (var proxyInd = 0; proxyInd < this.proxies.length; ++proxyInd) {
|
|
140
|
+
_loop_1(proxyInd);
|
|
141
|
+
}
|
|
142
|
+
return this.result;
|
|
143
|
+
};
|
|
144
|
+
return OverrideableBuilder3;
|
|
145
|
+
})()
|
|
146
|
+
);
|
|
147
|
+
exports.OverrideableBuilder = OverrideableBuilder2;
|
|
148
|
+
exports.default = OverrideableBuilder2;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// ../../node_modules/has-flag/index.js
|
|
153
|
+
var require_has_flag = __commonJS({
|
|
154
|
+
"../../node_modules/has-flag/index.js"(exports, module) {
|
|
155
|
+
"use strict";
|
|
156
|
+
module.exports = (flag, argv = process.argv) => {
|
|
157
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
158
|
+
const position = argv.indexOf(prefix + flag);
|
|
159
|
+
const terminatorPosition = argv.indexOf("--");
|
|
160
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// ../../node_modules/supports-color/index.js
|
|
166
|
+
var require_supports_color = __commonJS({
|
|
167
|
+
"../../node_modules/supports-color/index.js"(exports, module) {
|
|
168
|
+
"use strict";
|
|
169
|
+
var os = __require("os");
|
|
170
|
+
var tty = __require("tty");
|
|
171
|
+
var hasFlag = require_has_flag();
|
|
172
|
+
var { env } = process;
|
|
173
|
+
var forceColor;
|
|
174
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
175
|
+
forceColor = 0;
|
|
176
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
177
|
+
forceColor = 1;
|
|
178
|
+
}
|
|
179
|
+
if ("FORCE_COLOR" in env) {
|
|
180
|
+
if (env.FORCE_COLOR === "true") {
|
|
181
|
+
forceColor = 1;
|
|
182
|
+
} else if (env.FORCE_COLOR === "false") {
|
|
183
|
+
forceColor = 0;
|
|
184
|
+
} else {
|
|
185
|
+
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function translateLevel(level) {
|
|
189
|
+
if (level === 0) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
level,
|
|
194
|
+
hasBasic: true,
|
|
195
|
+
has256: level >= 2,
|
|
196
|
+
has16m: level >= 3
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function supportsColor(haveStream, streamIsTTY) {
|
|
200
|
+
if (forceColor === 0) {
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
204
|
+
return 3;
|
|
205
|
+
}
|
|
206
|
+
if (hasFlag("color=256")) {
|
|
207
|
+
return 2;
|
|
208
|
+
}
|
|
209
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
const min = forceColor || 0;
|
|
213
|
+
if (env.TERM === "dumb") {
|
|
214
|
+
return min;
|
|
215
|
+
}
|
|
216
|
+
if (process.platform === "win32") {
|
|
217
|
+
const osRelease = os.release().split(".");
|
|
218
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
219
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
220
|
+
}
|
|
221
|
+
return 1;
|
|
222
|
+
}
|
|
223
|
+
if ("CI" in env) {
|
|
224
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
225
|
+
return 1;
|
|
226
|
+
}
|
|
227
|
+
return min;
|
|
228
|
+
}
|
|
229
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
230
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
231
|
+
}
|
|
232
|
+
if (env.COLORTERM === "truecolor") {
|
|
233
|
+
return 3;
|
|
234
|
+
}
|
|
235
|
+
if ("TERM_PROGRAM" in env) {
|
|
236
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
237
|
+
switch (env.TERM_PROGRAM) {
|
|
238
|
+
case "iTerm.app":
|
|
239
|
+
return version >= 3 ? 3 : 2;
|
|
240
|
+
case "Apple_Terminal":
|
|
241
|
+
return 2;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
245
|
+
return 2;
|
|
246
|
+
}
|
|
247
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
248
|
+
return 1;
|
|
249
|
+
}
|
|
250
|
+
if ("COLORTERM" in env) {
|
|
251
|
+
return 1;
|
|
252
|
+
}
|
|
253
|
+
return min;
|
|
254
|
+
}
|
|
255
|
+
function getSupportLevel(stream) {
|
|
256
|
+
const level = supportsColor(stream, stream && stream.isTTY);
|
|
257
|
+
return translateLevel(level);
|
|
258
|
+
}
|
|
259
|
+
module.exports = {
|
|
260
|
+
supportsColor: getSupportLevel,
|
|
261
|
+
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
262
|
+
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// ../../shared/js/src/createPluginInit.ts
|
|
268
|
+
var import_supertokens_js_override = __toESM(require_build());
|
|
269
|
+
var createPluginInitFunction = (init2, getImplementation, getNormalisedConfig = (config2) => config2) => {
|
|
270
|
+
const getNormalizedImplementation = typeof getImplementation === "function" ? getImplementation : (_config) => getImplementation || {};
|
|
271
|
+
return (inputConfig) => {
|
|
272
|
+
const config2 = getNormalisedConfig(inputConfig || {});
|
|
273
|
+
const baseImplementation = getNormalizedImplementation(config2);
|
|
274
|
+
const overrideBuilder = new import_supertokens_js_override.OverrideableBuilder(baseImplementation);
|
|
275
|
+
if (inputConfig?.override) {
|
|
276
|
+
overrideBuilder.override(inputConfig.override);
|
|
277
|
+
}
|
|
278
|
+
const actualImplementation = overrideBuilder.build();
|
|
279
|
+
return init2(config2, actualImplementation);
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// ../../shared/nodejs/src/pluginUserMetadata.ts
|
|
284
|
+
import UserMetadata from "supertokens-node/recipe/usermetadata";
|
|
285
|
+
|
|
286
|
+
// ../../shared/nodejs/src/withRequestHandler.ts
|
|
287
|
+
var withRequestHandler = (fn) => {
|
|
288
|
+
return async (req, res, session, userContext) => {
|
|
289
|
+
const result = await fn(req, res, session, userContext);
|
|
290
|
+
if (result.status === "OK") {
|
|
291
|
+
res.setStatusCode(200);
|
|
292
|
+
} else {
|
|
293
|
+
res.setStatusCode(Number(result.code) || 400);
|
|
294
|
+
}
|
|
295
|
+
res.sendJSONResponse(result);
|
|
296
|
+
return null;
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// ../../shared/nodejs/src/log/logger.ts
|
|
301
|
+
import util from "util";
|
|
302
|
+
|
|
303
|
+
// ../../shared/nodejs/src/log/common.ts
|
|
304
|
+
function setup(env) {
|
|
305
|
+
createDebug.debug = createDebug;
|
|
306
|
+
createDebug.default = createDebug;
|
|
307
|
+
createDebug.coerce = coerce;
|
|
308
|
+
createDebug.disable = disable;
|
|
309
|
+
createDebug.enable = enable;
|
|
310
|
+
createDebug.enabled = enabled;
|
|
311
|
+
createDebug.humanize = env.humanize;
|
|
312
|
+
createDebug.destroy = destroy;
|
|
313
|
+
Object.keys(env).forEach((key) => {
|
|
314
|
+
createDebug[key] = env[key];
|
|
315
|
+
});
|
|
316
|
+
createDebug.names = [];
|
|
317
|
+
createDebug.skips = [];
|
|
318
|
+
createDebug.formatters = {};
|
|
319
|
+
function selectColor(namespace) {
|
|
320
|
+
let hash = 0;
|
|
321
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
322
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
323
|
+
hash |= 0;
|
|
324
|
+
}
|
|
325
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
326
|
+
}
|
|
327
|
+
createDebug.selectColor = selectColor;
|
|
328
|
+
function createDebug(namespace) {
|
|
329
|
+
let prevTime;
|
|
330
|
+
let enableOverride = null;
|
|
331
|
+
let namespacesCache;
|
|
332
|
+
let enabledCache;
|
|
333
|
+
function debug(...args) {
|
|
334
|
+
if (!debug.enabled) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const self = debug;
|
|
338
|
+
const curr = Number(/* @__PURE__ */ new Date());
|
|
339
|
+
const ms = curr - (prevTime || curr);
|
|
340
|
+
self.diff = ms;
|
|
341
|
+
self.prev = prevTime;
|
|
342
|
+
self.curr = curr;
|
|
343
|
+
prevTime = curr;
|
|
344
|
+
args[0] = createDebug.coerce(args[0]);
|
|
345
|
+
if (typeof args[0] !== "string") {
|
|
346
|
+
args.unshift("%O");
|
|
347
|
+
}
|
|
348
|
+
let index = 0;
|
|
349
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
350
|
+
if (match === "%%") {
|
|
351
|
+
return "%";
|
|
352
|
+
}
|
|
353
|
+
index++;
|
|
354
|
+
const formatter = createDebug.formatters[format];
|
|
355
|
+
if (typeof formatter === "function") {
|
|
356
|
+
const val = args[index];
|
|
357
|
+
match = formatter.call(self, val);
|
|
358
|
+
args.splice(index, 1);
|
|
359
|
+
index--;
|
|
360
|
+
}
|
|
361
|
+
return match;
|
|
362
|
+
});
|
|
363
|
+
createDebug.formatArgs.call(self, args);
|
|
364
|
+
const logFn = self.log || createDebug.log;
|
|
365
|
+
logFn.apply(self, args);
|
|
366
|
+
}
|
|
367
|
+
debug.namespace = namespace;
|
|
368
|
+
debug.useColors = createDebug.useColors();
|
|
369
|
+
debug.color = createDebug.selectColor(namespace);
|
|
370
|
+
debug.extend = extend;
|
|
371
|
+
debug.destroy = createDebug.destroy;
|
|
372
|
+
Object.defineProperty(debug, "enabled", {
|
|
373
|
+
enumerable: true,
|
|
374
|
+
configurable: false,
|
|
375
|
+
get: () => {
|
|
376
|
+
if (enableOverride !== null) {
|
|
377
|
+
return enableOverride;
|
|
378
|
+
}
|
|
379
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
380
|
+
namespacesCache = createDebug.namespaces;
|
|
381
|
+
enabledCache = createDebug.enabled(namespace);
|
|
382
|
+
}
|
|
383
|
+
return enabledCache;
|
|
384
|
+
},
|
|
385
|
+
set: (v) => {
|
|
386
|
+
enableOverride = v;
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
if (typeof createDebug.init === "function") {
|
|
390
|
+
createDebug.init(debug);
|
|
391
|
+
}
|
|
392
|
+
return debug;
|
|
393
|
+
}
|
|
394
|
+
function extend(namespace, delimiter) {
|
|
395
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
396
|
+
newDebug.log = this.log;
|
|
397
|
+
return newDebug;
|
|
398
|
+
}
|
|
399
|
+
function enable(namespaces) {
|
|
400
|
+
createDebug.save(namespaces);
|
|
401
|
+
createDebug.namespaces = namespaces;
|
|
402
|
+
createDebug.names = [];
|
|
403
|
+
createDebug.skips = [];
|
|
404
|
+
const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
|
|
405
|
+
for (const ns of split) {
|
|
406
|
+
if (ns[0] === "-") {
|
|
407
|
+
createDebug.skips.push(ns.slice(1));
|
|
408
|
+
} else {
|
|
409
|
+
createDebug.names.push(ns);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function matchesTemplate(search, template) {
|
|
414
|
+
let searchIndex = 0;
|
|
415
|
+
let templateIndex = 0;
|
|
416
|
+
let starIndex = -1;
|
|
417
|
+
let matchIndex = 0;
|
|
418
|
+
while (searchIndex < search.length) {
|
|
419
|
+
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
|
|
420
|
+
if (template[templateIndex] === "*") {
|
|
421
|
+
starIndex = templateIndex;
|
|
422
|
+
matchIndex = searchIndex;
|
|
423
|
+
templateIndex++;
|
|
424
|
+
} else {
|
|
425
|
+
searchIndex++;
|
|
426
|
+
templateIndex++;
|
|
427
|
+
}
|
|
428
|
+
} else if (starIndex !== -1) {
|
|
429
|
+
templateIndex = starIndex + 1;
|
|
430
|
+
matchIndex++;
|
|
431
|
+
searchIndex = matchIndex;
|
|
432
|
+
} else {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
while (templateIndex < template.length && template[templateIndex] === "*") {
|
|
437
|
+
templateIndex++;
|
|
438
|
+
}
|
|
439
|
+
return templateIndex === template.length;
|
|
440
|
+
}
|
|
441
|
+
function disable() {
|
|
442
|
+
const namespaces = [...createDebug.names, ...createDebug.skips.map((namespace) => "-" + namespace)].join(",");
|
|
443
|
+
createDebug.enable("");
|
|
444
|
+
return namespaces;
|
|
445
|
+
}
|
|
446
|
+
function enabled(name) {
|
|
447
|
+
for (const skip of createDebug.skips) {
|
|
448
|
+
if (matchesTemplate(name, skip)) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
for (const ns of createDebug.names) {
|
|
453
|
+
if (matchesTemplate(name, ns)) {
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
function coerce(val) {
|
|
460
|
+
if (val instanceof Error) {
|
|
461
|
+
return val.stack || val.message;
|
|
462
|
+
}
|
|
463
|
+
return val;
|
|
464
|
+
}
|
|
465
|
+
function destroy() {
|
|
466
|
+
console.warn(
|
|
467
|
+
"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
createDebug.enable(createDebug.load());
|
|
471
|
+
return createDebug;
|
|
472
|
+
}
|
|
473
|
+
var common_default = setup;
|
|
474
|
+
|
|
475
|
+
// ../../shared/nodejs/src/log/logger.ts
|
|
476
|
+
var BASIC_COLORS = [6, 2, 3, 4, 5, 1];
|
|
477
|
+
var EXTENDED_COLORS = [
|
|
478
|
+
20,
|
|
479
|
+
21,
|
|
480
|
+
26,
|
|
481
|
+
27,
|
|
482
|
+
32,
|
|
483
|
+
33,
|
|
484
|
+
38,
|
|
485
|
+
39,
|
|
486
|
+
40,
|
|
487
|
+
41,
|
|
488
|
+
42,
|
|
489
|
+
43,
|
|
490
|
+
44,
|
|
491
|
+
45,
|
|
492
|
+
56,
|
|
493
|
+
57,
|
|
494
|
+
62,
|
|
495
|
+
63,
|
|
496
|
+
68,
|
|
497
|
+
69,
|
|
498
|
+
74,
|
|
499
|
+
75,
|
|
500
|
+
76,
|
|
501
|
+
77,
|
|
502
|
+
78,
|
|
503
|
+
79,
|
|
504
|
+
80,
|
|
505
|
+
81,
|
|
506
|
+
92,
|
|
507
|
+
93,
|
|
508
|
+
98,
|
|
509
|
+
99,
|
|
510
|
+
112,
|
|
511
|
+
113,
|
|
512
|
+
128,
|
|
513
|
+
129,
|
|
514
|
+
134,
|
|
515
|
+
135,
|
|
516
|
+
148,
|
|
517
|
+
149,
|
|
518
|
+
160,
|
|
519
|
+
161,
|
|
520
|
+
162,
|
|
521
|
+
163,
|
|
522
|
+
164,
|
|
523
|
+
165,
|
|
524
|
+
166,
|
|
525
|
+
167,
|
|
526
|
+
168,
|
|
527
|
+
169,
|
|
528
|
+
170,
|
|
529
|
+
171,
|
|
530
|
+
172,
|
|
531
|
+
173,
|
|
532
|
+
178,
|
|
533
|
+
179,
|
|
534
|
+
184,
|
|
535
|
+
185,
|
|
536
|
+
196,
|
|
537
|
+
197,
|
|
538
|
+
198,
|
|
539
|
+
199,
|
|
540
|
+
200,
|
|
541
|
+
201,
|
|
542
|
+
202,
|
|
543
|
+
203,
|
|
544
|
+
204,
|
|
545
|
+
205,
|
|
546
|
+
206,
|
|
547
|
+
207,
|
|
548
|
+
208,
|
|
549
|
+
209,
|
|
550
|
+
214,
|
|
551
|
+
215,
|
|
552
|
+
220,
|
|
553
|
+
221
|
|
554
|
+
];
|
|
555
|
+
function supportsExtendedColors() {
|
|
556
|
+
try {
|
|
557
|
+
const supportsColor = require_supports_color();
|
|
558
|
+
return supportsColor && (supportsColor.stderr || supportsColor).level >= 2;
|
|
559
|
+
} catch {
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
function shouldUseColors() {
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
function formatArgs(args) {
|
|
567
|
+
const { namespace, useColors, color } = this;
|
|
568
|
+
if (useColors) {
|
|
569
|
+
const colorCode = color < 8 ? `3${color}` : `38;5;${color}`;
|
|
570
|
+
const prefix = `\x1B[${colorCode};1m${namespace}\x1B[0m`;
|
|
571
|
+
args[0] = `${prefix} ${args[0]}`.split("\n").join(`
|
|
572
|
+
${prefix} `);
|
|
573
|
+
args.push(`\x1B[${colorCode}m+${humanizeTime(this.diff)}\x1B[0m`);
|
|
574
|
+
} else {
|
|
575
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
576
|
+
args[0] = `${timestamp} ${namespace} ${args[0]}`;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function writeOutput(...args) {
|
|
580
|
+
process.stderr.write(util.format(...args) + "\n");
|
|
581
|
+
}
|
|
582
|
+
function saveConfig(namespaces) {
|
|
583
|
+
if (namespaces) {
|
|
584
|
+
process.env.DEBUG = namespaces;
|
|
585
|
+
} else {
|
|
586
|
+
delete process.env.DEBUG;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function loadConfig() {
|
|
590
|
+
return process.env.DEBUG;
|
|
591
|
+
}
|
|
592
|
+
function humanizeTime(milliseconds) {
|
|
593
|
+
if (milliseconds >= 1e3) {
|
|
594
|
+
const seconds = Math.round(milliseconds / 1e3);
|
|
595
|
+
return `${seconds}s`;
|
|
596
|
+
}
|
|
597
|
+
return `${milliseconds}ms`;
|
|
598
|
+
}
|
|
599
|
+
function createLoggerConfig() {
|
|
600
|
+
const colors = supportsExtendedColors() ? EXTENDED_COLORS : BASIC_COLORS;
|
|
601
|
+
return {
|
|
602
|
+
colors,
|
|
603
|
+
useColors: shouldUseColors,
|
|
604
|
+
formatArgs,
|
|
605
|
+
log: writeOutput,
|
|
606
|
+
save: saveConfig,
|
|
607
|
+
load: loadConfig,
|
|
608
|
+
humanize: humanizeTime
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
var config = createLoggerConfig();
|
|
612
|
+
var logger = common_default(config);
|
|
613
|
+
if (logger.formatters) {
|
|
614
|
+
logger.formatters.o = function(value) {
|
|
615
|
+
return util.inspect(value, { colors: this.useColors, compact: true }).split("\n").map((line) => line.trim()).join(" ");
|
|
616
|
+
};
|
|
617
|
+
logger.formatters.O = function(value) {
|
|
618
|
+
return util.inspect(value, { colors: this.useColors, compact: false });
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
var logger_default = logger;
|
|
622
|
+
|
|
623
|
+
// ../../shared/nodejs/src/log/index.ts
|
|
624
|
+
var log_default = logger_default;
|
|
625
|
+
|
|
626
|
+
// ../../shared/nodejs/src/logger.ts
|
|
627
|
+
var getFileLocation = () => {
|
|
628
|
+
let errorObject = new Error();
|
|
629
|
+
if (errorObject.stack === void 0) {
|
|
630
|
+
return "N/A";
|
|
631
|
+
}
|
|
632
|
+
let errorStack = errorObject.stack.split("\n");
|
|
633
|
+
for (let i = 1; i < errorStack.length; i++) {
|
|
634
|
+
if (!errorStack[i]?.includes("logger.js")) {
|
|
635
|
+
return errorStack[i]?.match(/(?<=\().+?(?=\))/g);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return "N/A";
|
|
639
|
+
};
|
|
640
|
+
var buildLogger = (pluginId, version, { fileLocation = true } = {}) => {
|
|
641
|
+
const namespace = `com.supertokens.plugin.${pluginId}`;
|
|
642
|
+
function logDebugMessage2(message) {
|
|
643
|
+
if (log_default.enabled(namespace)) {
|
|
644
|
+
log_default(namespace)(
|
|
645
|
+
`{t: "${(/* @__PURE__ */ new Date()).toISOString()}", message: "${message}", file: "${fileLocation ? getFileLocation() : "N/A"}" version: "${version}"}`
|
|
646
|
+
);
|
|
647
|
+
console.log();
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
function enableDebugLogs2() {
|
|
651
|
+
log_default.enable(namespace);
|
|
652
|
+
}
|
|
653
|
+
return {
|
|
654
|
+
logDebugMessage: logDebugMessage2,
|
|
655
|
+
enableDebugLogs: enableDebugLogs2
|
|
656
|
+
};
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
// src/plugin.ts
|
|
660
|
+
import { createInstance } from "@rownd/node";
|
|
661
|
+
import supertokens from "supertokens-node";
|
|
662
|
+
|
|
663
|
+
// src/constants.ts
|
|
664
|
+
var PLUGIN_ID = "supertokens-plugin-rownd";
|
|
665
|
+
var PLUGIN_SDK_VERSION = ["23.0.0", "23.0.1", ">=23.0.1"];
|
|
666
|
+
var HANDLE_BASE_PATH = "/plugin/rownd";
|
|
667
|
+
var PUBLIC_TENANT_ID = "public";
|
|
668
|
+
|
|
669
|
+
// src/logger.ts
|
|
670
|
+
var { logDebugMessage, enableDebugLogs } = buildLogger(
|
|
671
|
+
PLUGIN_ID,
|
|
672
|
+
PLUGIN_SDK_VERSION
|
|
673
|
+
);
|
|
674
|
+
|
|
675
|
+
// src/plugin.ts
|
|
676
|
+
import Session from "supertokens-node/recipe/session";
|
|
677
|
+
|
|
678
|
+
// src/telemetry/axiomTelemetryClient.ts
|
|
679
|
+
var DEFAULT_AXIOM_URL = "https://api.axiom.co/v1/datasets";
|
|
680
|
+
var AxiomTelemetryClient = class {
|
|
681
|
+
constructor(token, dataset, endpoint) {
|
|
682
|
+
this.token = token;
|
|
683
|
+
this.dataset = dataset;
|
|
684
|
+
const baseUrl = (endpoint ?? DEFAULT_AXIOM_URL).replace(/\/$/, "");
|
|
685
|
+
this.url = `${baseUrl}/${dataset}/ingest`;
|
|
686
|
+
}
|
|
687
|
+
token;
|
|
688
|
+
dataset;
|
|
689
|
+
url;
|
|
690
|
+
async recordEvent(event) {
|
|
691
|
+
await fetch(this.url, {
|
|
692
|
+
method: "POST",
|
|
693
|
+
headers: {
|
|
694
|
+
Authorization: `Bearer ${this.token}`,
|
|
695
|
+
"Content-Type": "application/json"
|
|
696
|
+
},
|
|
697
|
+
body: JSON.stringify([
|
|
698
|
+
{
|
|
699
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
700
|
+
plugin: PLUGIN_ID,
|
|
701
|
+
...event
|
|
702
|
+
}
|
|
703
|
+
])
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
// src/telemetry/openTelemetryClient.ts
|
|
709
|
+
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
710
|
+
var OpenTelemetryClient = class {
|
|
711
|
+
recordEvent(event) {
|
|
712
|
+
const tracer = trace.getTracer("supertokens-plugin-rownd", "0.1.0");
|
|
713
|
+
const span = tracer.startSpan("rownd.migrate");
|
|
714
|
+
span.setAttributes({
|
|
715
|
+
"rownd.outcome": event.outcome,
|
|
716
|
+
"rownd.duration_ms": event.durationMs,
|
|
717
|
+
"rownd.tenant_id": event.tenantId ?? "",
|
|
718
|
+
"rownd.rownd_user_id": event.rowndUserId ?? "",
|
|
719
|
+
"rownd.supertokens_user_id": event.superTokensUserId ?? ""
|
|
720
|
+
});
|
|
721
|
+
if (event.outcome === "error") {
|
|
722
|
+
const err = new Error(event.error.message);
|
|
723
|
+
if (event.error.name) {
|
|
724
|
+
err.name = event.error.name;
|
|
725
|
+
}
|
|
726
|
+
span.recordException(err);
|
|
727
|
+
span.setStatus({
|
|
728
|
+
code: SpanStatusCode.ERROR,
|
|
729
|
+
message: event.error.message
|
|
730
|
+
});
|
|
731
|
+
} else {
|
|
732
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
733
|
+
}
|
|
734
|
+
span.end();
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
// src/telemetry/createTelemetryClient.ts
|
|
739
|
+
function createClient(telemetryConfig) {
|
|
740
|
+
let client;
|
|
741
|
+
if (telemetryConfig?.provider === "opentelemetry") {
|
|
742
|
+
client = new OpenTelemetryClient();
|
|
743
|
+
} else if (telemetryConfig?.provider === "axiom") {
|
|
744
|
+
client = new AxiomTelemetryClient(
|
|
745
|
+
telemetryConfig.token,
|
|
746
|
+
telemetryConfig.dataset,
|
|
747
|
+
telemetryConfig.url
|
|
748
|
+
);
|
|
749
|
+
} else if (telemetryConfig?.provider === "custom") {
|
|
750
|
+
client = telemetryConfig.factory();
|
|
751
|
+
}
|
|
752
|
+
return {
|
|
753
|
+
recordSuccess: (event) => {
|
|
754
|
+
if (!client) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
safeRecordEvent(client, event, "success");
|
|
758
|
+
},
|
|
759
|
+
recordError: (input) => {
|
|
760
|
+
if (!client) {
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
const event = {
|
|
764
|
+
outcome: "error",
|
|
765
|
+
durationMs: Date.now() - input.startedAt,
|
|
766
|
+
tenantId: input.tenantId,
|
|
767
|
+
rowndUserId: input.rowndUserId,
|
|
768
|
+
superTokensUserId: input.superTokensUserId,
|
|
769
|
+
error: {
|
|
770
|
+
message: input.error instanceof Error ? input.error.message : "Unknown error",
|
|
771
|
+
name: input.error instanceof Error ? input.error.name : void 0
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
safeRecordEvent(client, event, "error");
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
function safeRecordEvent(client, event, outcome) {
|
|
779
|
+
try {
|
|
780
|
+
Promise.resolve(client.recordEvent(event)).catch((error) => {
|
|
781
|
+
logDebugMessage(
|
|
782
|
+
`Failed to record telemetry ${outcome} event. Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
783
|
+
);
|
|
784
|
+
});
|
|
785
|
+
} catch (error) {
|
|
786
|
+
logDebugMessage(
|
|
787
|
+
`Failed to record telemetry ${outcome} event. Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// src/errors.ts
|
|
793
|
+
var ROWND_PLUGIN_ERROR_MESSAGES = {
|
|
794
|
+
MISSING_AUTHORIZATION_HEADER: "Missing authorization header",
|
|
795
|
+
INVALID_TOKEN: "Invalid token",
|
|
796
|
+
ROWND_USER_NOT_FOUND: "User not found in Rownd"
|
|
797
|
+
};
|
|
798
|
+
var RowndPluginError = class extends Error {
|
|
799
|
+
constructor(type) {
|
|
800
|
+
super(ROWND_PLUGIN_ERROR_MESSAGES[type]);
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
// src/pluginImplementation.ts
|
|
805
|
+
var rowndClient;
|
|
806
|
+
function setRowndClient(client) {
|
|
807
|
+
rowndClient = client;
|
|
808
|
+
}
|
|
809
|
+
function getRowndClient() {
|
|
810
|
+
if (!rowndClient) {
|
|
811
|
+
throw new Error("Rownd client not initialized");
|
|
812
|
+
}
|
|
813
|
+
return rowndClient;
|
|
814
|
+
}
|
|
815
|
+
async function parseRequest(req) {
|
|
816
|
+
const authHeader = req.getHeaderValue("authorization");
|
|
817
|
+
if (!authHeader) {
|
|
818
|
+
throw new RowndPluginError("MISSING_AUTHORIZATION_HEADER");
|
|
819
|
+
}
|
|
820
|
+
const token = authHeader.replace(/^Bearer /i, "");
|
|
821
|
+
if (!token) {
|
|
822
|
+
throw new RowndPluginError("INVALID_TOKEN");
|
|
823
|
+
}
|
|
824
|
+
return {
|
|
825
|
+
token
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
function mapRowndUserToSuperTokens(rowndUser) {
|
|
829
|
+
const loginMethods = [];
|
|
830
|
+
const rowndUserData = rowndUser.data || {};
|
|
831
|
+
const rowndUserVerifiedData = rowndUser.verified_data || {};
|
|
832
|
+
if (!rowndUserData.user_id) {
|
|
833
|
+
throw new Error("Rownd user has no user_id");
|
|
834
|
+
}
|
|
835
|
+
if (rowndUserData.google_id) {
|
|
836
|
+
if (!rowndUserData.email) {
|
|
837
|
+
throw new Error("Rownd Google user is missing email");
|
|
838
|
+
}
|
|
839
|
+
loginMethods.push({
|
|
840
|
+
recipeId: "thirdparty",
|
|
841
|
+
thirdPartyId: "google",
|
|
842
|
+
thirdPartyUserId: rowndUserData.google_id,
|
|
843
|
+
email: rowndUserData.email,
|
|
844
|
+
isVerified: !!rowndUserVerifiedData.google_id
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
if (rowndUserData.apple_id) {
|
|
848
|
+
if (!rowndUserData.email) {
|
|
849
|
+
throw new Error("Rownd Apple user is missing email");
|
|
850
|
+
}
|
|
851
|
+
loginMethods.push({
|
|
852
|
+
recipeId: "thirdparty",
|
|
853
|
+
thirdPartyId: "apple",
|
|
854
|
+
thirdPartyUserId: rowndUserData.apple_id,
|
|
855
|
+
email: rowndUserData.email,
|
|
856
|
+
isVerified: !!rowndUserVerifiedData.apple_id
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
if (rowndUserData.phone_number) {
|
|
860
|
+
loginMethods.push({
|
|
861
|
+
recipeId: "passwordless",
|
|
862
|
+
phoneNumber: rowndUserData.phone_number,
|
|
863
|
+
isVerified: !!rowndUserVerifiedData.phone_number
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
if (rowndUserData.email && loginMethods.length === 0) {
|
|
867
|
+
loginMethods.push({
|
|
868
|
+
recipeId: "passwordless",
|
|
869
|
+
email: rowndUserData.email,
|
|
870
|
+
isVerified: !!rowndUserVerifiedData.email
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
if (loginMethods.length === 0) {
|
|
874
|
+
throw new Error("No valid login methods found in Rownd user data");
|
|
875
|
+
}
|
|
876
|
+
const rowndUserMeta = rowndUser.meta || {};
|
|
877
|
+
const rowndUserAttributes = rowndUser.attributes || {};
|
|
878
|
+
const userMetadata = {
|
|
879
|
+
data: {
|
|
880
|
+
...rowndUserData
|
|
881
|
+
},
|
|
882
|
+
meta: {
|
|
883
|
+
...rowndUserMeta
|
|
884
|
+
},
|
|
885
|
+
verified_data: {
|
|
886
|
+
...rowndUserVerifiedData
|
|
887
|
+
},
|
|
888
|
+
attributes: {
|
|
889
|
+
...rowndUserAttributes
|
|
890
|
+
},
|
|
891
|
+
rownd_migrated: true,
|
|
892
|
+
rownd_user_id: rowndUserData.user_id
|
|
893
|
+
};
|
|
894
|
+
return {
|
|
895
|
+
externalUserId: rowndUserData.user_id,
|
|
896
|
+
loginMethods,
|
|
897
|
+
userMetadata
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
async function importUser(stUser, config2) {
|
|
901
|
+
const headers = {
|
|
902
|
+
"Content-Type": "application/json"
|
|
903
|
+
};
|
|
904
|
+
if (config2.apiKey) {
|
|
905
|
+
headers["api-key"] = config2.apiKey;
|
|
906
|
+
}
|
|
907
|
+
const response = await fetch(`${config2.connectionURI}/bulk-import/import`, {
|
|
908
|
+
method: "POST",
|
|
909
|
+
headers,
|
|
910
|
+
body: JSON.stringify(stUser)
|
|
911
|
+
});
|
|
912
|
+
if (!response.ok) {
|
|
913
|
+
const errorText = await response.text();
|
|
914
|
+
throw new Error(
|
|
915
|
+
`Bulk import failed with status ${response.status}: ${errorText}`
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
const importResponse = await response.json();
|
|
919
|
+
if (importResponse.status !== "OK" || !importResponse.user) {
|
|
920
|
+
throw new Error(
|
|
921
|
+
`Bulk import failed: ${importResponse.message || "Missing user in response"}`
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
return importResponse.user;
|
|
925
|
+
}
|
|
926
|
+
async function validateRowndToken(token) {
|
|
927
|
+
const client = getRowndClient();
|
|
928
|
+
const tokenInfo = await client.validateToken(token);
|
|
929
|
+
return tokenInfo.user_id;
|
|
930
|
+
}
|
|
931
|
+
async function fetchRowndUserInfo(userId) {
|
|
932
|
+
const client = getRowndClient();
|
|
933
|
+
const rowndUser = await client.fetchUserInfo({ user_id: userId });
|
|
934
|
+
if (!rowndUser) {
|
|
935
|
+
throw new RowndPluginError("ROWND_USER_NOT_FOUND");
|
|
936
|
+
}
|
|
937
|
+
return rowndUser;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// src/plugin.ts
|
|
941
|
+
var init = createPluginInitFunction(
|
|
942
|
+
(config2) => {
|
|
943
|
+
const rowndClient2 = createInstance({
|
|
944
|
+
app_key: config2.rowndAppKey,
|
|
945
|
+
app_secret: config2.rowndAppSecret
|
|
946
|
+
});
|
|
947
|
+
const telemetryClient = createClient(config2.telemetry);
|
|
948
|
+
setRowndClient(rowndClient2);
|
|
949
|
+
if (config2.enableDebugLogs) {
|
|
950
|
+
enableDebugLogs();
|
|
951
|
+
}
|
|
952
|
+
logDebugMessage("Rownd plugin init complete");
|
|
953
|
+
return {
|
|
954
|
+
id: PLUGIN_ID,
|
|
955
|
+
compatibleSDKVersions: PLUGIN_SDK_VERSION,
|
|
956
|
+
init: async () => {
|
|
957
|
+
if (!supertokens.isRecipeInitialized("session")) {
|
|
958
|
+
console.warn(
|
|
959
|
+
"RowndMigrationPlugin: Session recipe is not initialized. Session migration will fail."
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
},
|
|
963
|
+
routeHandlers(config3) {
|
|
964
|
+
const apiBasePath = config3.appInfo.apiBasePath.getAsStringDangerous();
|
|
965
|
+
return {
|
|
966
|
+
status: "OK",
|
|
967
|
+
routeHandlers: [
|
|
968
|
+
{
|
|
969
|
+
path: `${apiBasePath}${HANDLE_BASE_PATH}/migrate`,
|
|
970
|
+
method: "post",
|
|
971
|
+
handler: withRequestHandler(
|
|
972
|
+
async (req, res, _session, userContext) => {
|
|
973
|
+
const startedAt = Date.now();
|
|
974
|
+
let tenantId = PUBLIC_TENANT_ID;
|
|
975
|
+
let rowndUserId;
|
|
976
|
+
let superTokensUserId;
|
|
977
|
+
let user;
|
|
978
|
+
let recipeUserId;
|
|
979
|
+
try {
|
|
980
|
+
if (!config3.supertokens) {
|
|
981
|
+
throw new Error("Supertokens config not found");
|
|
982
|
+
}
|
|
983
|
+
const parsed = await parseRequest(req);
|
|
984
|
+
rowndUserId = await validateRowndToken(parsed.token);
|
|
985
|
+
user = await supertokens.getUser(rowndUserId, userContext);
|
|
986
|
+
if (!user) {
|
|
987
|
+
const rowndUser = await fetchRowndUserInfo(rowndUserId);
|
|
988
|
+
const stUserImport = mapRowndUserToSuperTokens(rowndUser);
|
|
989
|
+
const importedUser = await importUser(
|
|
990
|
+
stUserImport,
|
|
991
|
+
config3.supertokens
|
|
992
|
+
);
|
|
993
|
+
superTokensUserId = importedUser.id;
|
|
994
|
+
if (importedUser.loginMethods[0]?.recipeUserId) {
|
|
995
|
+
recipeUserId = supertokens.convertToRecipeUserId(
|
|
996
|
+
importedUser.loginMethods[0].recipeUserId
|
|
997
|
+
);
|
|
998
|
+
}
|
|
999
|
+
logDebugMessage(
|
|
1000
|
+
`User migrated successfully. tenantId: ${PUBLIC_TENANT_ID}, rowndUserId: ${rowndUserId}`
|
|
1001
|
+
);
|
|
1002
|
+
} else {
|
|
1003
|
+
superTokensUserId = user.id;
|
|
1004
|
+
recipeUserId = user.loginMethods[0]?.recipeUserId;
|
|
1005
|
+
logDebugMessage(
|
|
1006
|
+
`User already migrated. tenantId: ${PUBLIC_TENANT_ID}, rowndUserId: ${rowndUserId}`
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
if (!recipeUserId) {
|
|
1010
|
+
throw new Error("User not found or has no login methods");
|
|
1011
|
+
}
|
|
1012
|
+
await Session.createNewSession(
|
|
1013
|
+
req,
|
|
1014
|
+
res,
|
|
1015
|
+
PUBLIC_TENANT_ID,
|
|
1016
|
+
recipeUserId,
|
|
1017
|
+
{},
|
|
1018
|
+
{},
|
|
1019
|
+
userContext
|
|
1020
|
+
);
|
|
1021
|
+
logDebugMessage(
|
|
1022
|
+
`Session migrated successfully. tenantId: ${PUBLIC_TENANT_ID}, userId: ${superTokensUserId}`
|
|
1023
|
+
);
|
|
1024
|
+
telemetryClient.recordSuccess({
|
|
1025
|
+
outcome: "success",
|
|
1026
|
+
durationMs: Date.now() - startedAt,
|
|
1027
|
+
tenantId,
|
|
1028
|
+
rowndUserId,
|
|
1029
|
+
superTokensUserId
|
|
1030
|
+
});
|
|
1031
|
+
return { status: "OK" };
|
|
1032
|
+
} catch (error) {
|
|
1033
|
+
logDebugMessage(
|
|
1034
|
+
`Migration failed. Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1035
|
+
);
|
|
1036
|
+
telemetryClient.recordError({
|
|
1037
|
+
error,
|
|
1038
|
+
startedAt,
|
|
1039
|
+
tenantId,
|
|
1040
|
+
rowndUserId,
|
|
1041
|
+
superTokensUserId
|
|
1042
|
+
});
|
|
1043
|
+
return {
|
|
1044
|
+
status: "ERROR",
|
|
1045
|
+
message: error instanceof RowndPluginError ? error.message : "Migration failed"
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
)
|
|
1050
|
+
}
|
|
1051
|
+
]
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
},
|
|
1056
|
+
() => ({}),
|
|
1057
|
+
(config2) => {
|
|
1058
|
+
if (!config2?.rowndAppKey || !config2?.rowndAppSecret) {
|
|
1059
|
+
throw new Error("Missing rowndAppKey or rowndAppSecret in plugin config");
|
|
1060
|
+
}
|
|
1061
|
+
if (config2.telemetry?.provider === "axiom") {
|
|
1062
|
+
if (!config2.telemetry.token || !config2.telemetry.dataset) {
|
|
1063
|
+
throw new Error(
|
|
1064
|
+
"Missing telemetry axiom token or dataset in plugin config"
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
if (config2.telemetry?.provider === "custom") {
|
|
1069
|
+
if (typeof config2.telemetry.factory !== "function") {
|
|
1070
|
+
throw new Error(
|
|
1071
|
+
"Missing telemetry custom factory function in plugin config"
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
return {
|
|
1076
|
+
rowndAppKey: config2.rowndAppKey,
|
|
1077
|
+
rowndAppSecret: config2.rowndAppSecret,
|
|
1078
|
+
enableDebugLogs: config2.enableDebugLogs,
|
|
1079
|
+
telemetry: config2.telemetry
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
);
|
|
1083
|
+
|
|
1084
|
+
// src/index.ts
|
|
1085
|
+
var index_default = { init };
|
|
1086
|
+
export {
|
|
1087
|
+
HANDLE_BASE_PATH,
|
|
1088
|
+
PLUGIN_ID,
|
|
1089
|
+
PLUGIN_SDK_VERSION,
|
|
1090
|
+
PUBLIC_TENANT_ID,
|
|
1091
|
+
ROWND_PLUGIN_ERROR_MESSAGES,
|
|
1092
|
+
RowndPluginError,
|
|
1093
|
+
index_default as default,
|
|
1094
|
+
init
|
|
1095
|
+
};
|