@restorecommerce/facade 1.2.0 → 1.3.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.
Files changed (254) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.cjs +13 -0
  3. package/CHANGELOG.md +22 -0
  4. package/codegen/index.d.ts +1 -1
  5. package/codegen/index.js +18 -44
  6. package/debug-run.ts +7 -6
  7. package/dist/gql/index.d.ts +1 -1
  8. package/dist/gql/index.js +1 -17
  9. package/dist/gql/protos/federation.d.ts +3 -3
  10. package/dist/gql/protos/federation.js +16 -24
  11. package/dist/gql/protos/graphql.d.ts +4 -4
  12. package/dist/gql/protos/graphql.js +64 -42
  13. package/dist/gql/protos/index.d.ts +6 -6
  14. package/dist/gql/protos/index.js +6 -22
  15. package/dist/gql/protos/registry.d.ts +6 -6
  16. package/dist/gql/protos/registry.js +157 -176
  17. package/dist/gql/protos/resolvers.d.ts +3 -3
  18. package/dist/gql/protos/resolvers.js +78 -104
  19. package/dist/gql/protos/schema.d.ts +4 -4
  20. package/dist/gql/protos/schema.js +40 -53
  21. package/dist/gql/protos/types.d.ts +3 -3
  22. package/dist/gql/protos/types.js +1 -4
  23. package/dist/gql/protos/utils.d.ts +3 -3
  24. package/dist/gql/protos/utils.js +23 -62
  25. package/dist/gql/types/AccessControlTypes.js +13 -16
  26. package/dist/gql/types/DateType.js +4 -7
  27. package/dist/gql/types/FilterType.js +7 -10
  28. package/dist/gql/types/MetaType.js +8 -11
  29. package/dist/gql/types/ScopeType.js +4 -7
  30. package/dist/gql/types/SortType.js +5 -8
  31. package/dist/gql/types/StatusType.js +4 -7
  32. package/dist/gql/types/index.d.ts +7 -7
  33. package/dist/gql/types/index.js +7 -23
  34. package/dist/index.d.ts +14 -14
  35. package/dist/index.js +195 -207
  36. package/dist/interfaces.d.ts +8 -8
  37. package/dist/interfaces.js +1 -2
  38. package/dist/middlewares/index.d.ts +1 -1
  39. package/dist/middlewares/index.js +1 -17
  40. package/dist/middlewares/req-res-logger/index.d.ts +2 -2
  41. package/dist/middlewares/req-res-logger/index.js +33 -31
  42. package/dist/modules/access-control/gql/federation.d.ts +1 -1
  43. package/dist/modules/access-control/gql/federation.js +10 -17
  44. package/dist/modules/access-control/gql/schema.d.ts +1 -1
  45. package/dist/modules/access-control/gql/schema.generated.d.ts +136 -110
  46. package/dist/modules/access-control/gql/schema.generated.js +22 -25
  47. package/dist/modules/access-control/gql/schema.js +5 -9
  48. package/dist/modules/access-control/gql/types.d.ts +2 -2
  49. package/dist/modules/access-control/gql/types.js +13 -17
  50. package/dist/modules/access-control/grpc/index.d.ts +5 -5
  51. package/dist/modules/access-control/grpc/index.js +10 -14
  52. package/dist/modules/access-control/index.d.ts +2 -2
  53. package/dist/modules/access-control/index.js +20 -17
  54. package/dist/modules/access-control/interfaces.d.ts +3 -3
  55. package/dist/modules/access-control/interfaces.js +1 -4
  56. package/dist/modules/catalog/gql/federation.d.ts +1 -1
  57. package/dist/modules/catalog/gql/federation.js +10 -17
  58. package/dist/modules/catalog/gql/schema.d.ts +1 -1
  59. package/dist/modules/catalog/gql/schema.generated.d.ts +252 -226
  60. package/dist/modules/catalog/gql/schema.generated.js +20 -23
  61. package/dist/modules/catalog/gql/schema.js +5 -9
  62. package/dist/modules/catalog/gql/types.d.ts +2 -2
  63. package/dist/modules/catalog/gql/types.js +15 -19
  64. package/dist/modules/catalog/grpc/index.d.ts +6 -6
  65. package/dist/modules/catalog/grpc/index.js +12 -16
  66. package/dist/modules/catalog/index.d.ts +2 -2
  67. package/dist/modules/catalog/index.js +20 -17
  68. package/dist/modules/catalog/interfaces.d.ts +3 -3
  69. package/dist/modules/catalog/interfaces.js +1 -4
  70. package/dist/modules/facade-status/gql/index.js +8 -14
  71. package/dist/modules/facade-status/gql/resolvers.d.ts +1 -1
  72. package/dist/modules/facade-status/gql/resolvers.js +14 -8
  73. package/dist/modules/facade-status/gql/schema.d.ts +1 -1
  74. package/dist/modules/facade-status/gql/schema.generated.d.ts +34 -11
  75. package/dist/modules/facade-status/gql/schema.generated.js +1 -2
  76. package/dist/modules/facade-status/gql/schema.js +6 -9
  77. package/dist/modules/facade-status/gql/types.js +3 -6
  78. package/dist/modules/facade-status/index.d.ts +1 -1
  79. package/dist/modules/facade-status/index.js +4 -7
  80. package/dist/modules/facade-status/interfaces.d.ts +1 -1
  81. package/dist/modules/facade-status/interfaces.js +1 -2
  82. package/dist/modules/fulfillment/gql/federation.d.ts +1 -1
  83. package/dist/modules/fulfillment/gql/federation.js +10 -17
  84. package/dist/modules/fulfillment/gql/schema.d.ts +1 -1
  85. package/dist/modules/fulfillment/gql/schema.generated.d.ts +249 -223
  86. package/dist/modules/fulfillment/gql/schema.generated.js +20 -23
  87. package/dist/modules/fulfillment/gql/schema.js +5 -9
  88. package/dist/modules/fulfillment/gql/types.d.ts +2 -2
  89. package/dist/modules/fulfillment/gql/types.js +11 -15
  90. package/dist/modules/fulfillment/grpc/index.d.ts +3 -3
  91. package/dist/modules/fulfillment/grpc/index.js +6 -10
  92. package/dist/modules/fulfillment/index.d.ts +2 -2
  93. package/dist/modules/fulfillment/index.js +20 -17
  94. package/dist/modules/fulfillment/interfaces.d.ts +3 -3
  95. package/dist/modules/fulfillment/interfaces.js +1 -4
  96. package/dist/modules/identity/api-key/api-key.d.ts +2 -2
  97. package/dist/modules/identity/api-key/api-key.js +45 -65
  98. package/dist/modules/identity/gql/federation.d.ts +2 -2
  99. package/dist/modules/identity/gql/federation.js +5 -9
  100. package/dist/modules/identity/gql/schema.d.ts +1 -1
  101. package/dist/modules/identity/gql/schema.generated.d.ts +284 -255
  102. package/dist/modules/identity/gql/schema.generated.js +20 -23
  103. package/dist/modules/identity/gql/schema.js +5 -9
  104. package/dist/modules/identity/gql/types.d.ts +2 -2
  105. package/dist/modules/identity/gql/types.js +17 -21
  106. package/dist/modules/identity/grpc/index.d.ts +6 -6
  107. package/dist/modules/identity/grpc/index.js +12 -16
  108. package/dist/modules/identity/index.d.ts +4 -4
  109. package/dist/modules/identity/index.js +24 -21
  110. package/dist/modules/identity/interfaces.d.ts +5 -5
  111. package/dist/modules/identity/interfaces.js +1 -4
  112. package/dist/modules/identity/oauth/oauth.d.ts +4 -4
  113. package/dist/modules/identity/oauth/oauth.js +109 -135
  114. package/dist/modules/identity/oidc/adapter.d.ts +3 -3
  115. package/dist/modules/identity/oidc/adapter.js +111 -92
  116. package/dist/modules/identity/oidc/in-memory-adapter.d.ts +1 -1
  117. package/dist/modules/identity/oidc/in-memory-adapter.js +64 -50
  118. package/dist/modules/identity/oidc/index.d.ts +6 -6
  119. package/dist/modules/identity/oidc/index.js +29 -30
  120. package/dist/modules/identity/oidc/interfaces.d.ts +6 -6
  121. package/dist/modules/identity/oidc/interfaces.js +2 -6
  122. package/dist/modules/identity/oidc/password-grant.d.ts +1 -1
  123. package/dist/modules/identity/oidc/password-grant.js +43 -66
  124. package/dist/modules/identity/oidc/router.d.ts +6 -6
  125. package/dist/modules/identity/oidc/router.js +31 -26
  126. package/dist/modules/identity/oidc/templates.d.ts +1 -1
  127. package/dist/modules/identity/oidc/templates.js +45 -41
  128. package/dist/modules/identity/oidc/user.d.ts +4 -4
  129. package/dist/modules/identity/oidc/user.js +31 -29
  130. package/dist/modules/identity/oidc/utils.d.ts +2 -2
  131. package/dist/modules/identity/oidc/utils.js +6 -13
  132. package/dist/modules/index.d.ts +13 -13
  133. package/dist/modules/index.js +13 -29
  134. package/dist/modules/indexing/gql/federation.d.ts +1 -1
  135. package/dist/modules/indexing/gql/federation.js +10 -17
  136. package/dist/modules/indexing/gql/schema.d.ts +1 -1
  137. package/dist/modules/indexing/gql/schema.generated.d.ts +45 -19
  138. package/dist/modules/indexing/gql/schema.generated.js +2 -5
  139. package/dist/modules/indexing/gql/schema.js +5 -9
  140. package/dist/modules/indexing/gql/types.d.ts +2 -2
  141. package/dist/modules/indexing/gql/types.js +7 -11
  142. package/dist/modules/indexing/grpc/index.d.ts +2 -2
  143. package/dist/modules/indexing/grpc/index.js +4 -8
  144. package/dist/modules/indexing/index.d.ts +2 -2
  145. package/dist/modules/indexing/index.js +20 -17
  146. package/dist/modules/indexing/interfaces.d.ts +3 -3
  147. package/dist/modules/indexing/interfaces.js +1 -4
  148. package/dist/modules/invoicing/gql/federation.d.ts +1 -1
  149. package/dist/modules/invoicing/gql/federation.js +10 -17
  150. package/dist/modules/invoicing/gql/schema.d.ts +1 -1
  151. package/dist/modules/invoicing/gql/schema.generated.d.ts +209 -183
  152. package/dist/modules/invoicing/gql/schema.generated.js +20 -23
  153. package/dist/modules/invoicing/gql/schema.js +5 -9
  154. package/dist/modules/invoicing/gql/types.d.ts +2 -2
  155. package/dist/modules/invoicing/gql/types.js +7 -11
  156. package/dist/modules/invoicing/grpc/index.d.ts +2 -2
  157. package/dist/modules/invoicing/grpc/index.js +4 -8
  158. package/dist/modules/invoicing/index.d.ts +2 -2
  159. package/dist/modules/invoicing/index.js +20 -17
  160. package/dist/modules/invoicing/interfaces.d.ts +3 -3
  161. package/dist/modules/invoicing/interfaces.js +1 -4
  162. package/dist/modules/notification/gql/federation.d.ts +1 -1
  163. package/dist/modules/notification/gql/federation.js +10 -17
  164. package/dist/modules/notification/gql/schema.d.ts +1 -1
  165. package/dist/modules/notification/gql/schema.generated.d.ts +100 -74
  166. package/dist/modules/notification/gql/schema.generated.js +18 -21
  167. package/dist/modules/notification/gql/schema.js +5 -9
  168. package/dist/modules/notification/gql/types.d.ts +2 -2
  169. package/dist/modules/notification/gql/types.js +7 -11
  170. package/dist/modules/notification/grpc/index.d.ts +2 -2
  171. package/dist/modules/notification/grpc/index.js +4 -8
  172. package/dist/modules/notification/index.d.ts +2 -2
  173. package/dist/modules/notification/index.js +20 -17
  174. package/dist/modules/notification/interfaces.d.ts +3 -3
  175. package/dist/modules/notification/interfaces.js +1 -4
  176. package/dist/modules/ordering/gql/federation.d.ts +1 -1
  177. package/dist/modules/ordering/gql/federation.js +10 -17
  178. package/dist/modules/ordering/gql/schema.d.ts +1 -1
  179. package/dist/modules/ordering/gql/schema.generated.d.ts +221 -195
  180. package/dist/modules/ordering/gql/schema.generated.js +22 -25
  181. package/dist/modules/ordering/gql/schema.js +5 -9
  182. package/dist/modules/ordering/gql/types.d.ts +2 -2
  183. package/dist/modules/ordering/gql/types.js +7 -11
  184. package/dist/modules/ordering/grpc/index.d.ts +2 -2
  185. package/dist/modules/ordering/grpc/index.js +4 -8
  186. package/dist/modules/ordering/index.d.ts +2 -2
  187. package/dist/modules/ordering/index.js +20 -17
  188. package/dist/modules/ordering/interfaces.d.ts +3 -3
  189. package/dist/modules/ordering/interfaces.js +1 -4
  190. package/dist/modules/ostorage/gql/federation.d.ts +1 -1
  191. package/dist/modules/ostorage/gql/federation.js +10 -17
  192. package/dist/modules/ostorage/gql/schema.d.ts +1 -1
  193. package/dist/modules/ostorage/gql/schema.generated.d.ts +126 -94
  194. package/dist/modules/ostorage/gql/schema.generated.js +8 -11
  195. package/dist/modules/ostorage/gql/schema.js +5 -9
  196. package/dist/modules/ostorage/gql/types.d.ts +2 -2
  197. package/dist/modules/ostorage/gql/types.js +7 -11
  198. package/dist/modules/ostorage/grpc/index.d.ts +2 -2
  199. package/dist/modules/ostorage/grpc/index.js +4 -8
  200. package/dist/modules/ostorage/index.d.ts +2 -2
  201. package/dist/modules/ostorage/index.js +20 -17
  202. package/dist/modules/ostorage/interfaces.d.ts +3 -3
  203. package/dist/modules/ostorage/interfaces.js +1 -4
  204. package/dist/modules/payment/gql/federation.d.ts +1 -1
  205. package/dist/modules/payment/gql/federation.js +10 -17
  206. package/dist/modules/payment/gql/schema.d.ts +1 -1
  207. package/dist/modules/payment/gql/schema.generated.d.ts +67 -44
  208. package/dist/modules/payment/gql/schema.generated.js +4 -7
  209. package/dist/modules/payment/gql/schema.js +5 -9
  210. package/dist/modules/payment/gql/types.d.ts +2 -2
  211. package/dist/modules/payment/gql/types.js +7 -11
  212. package/dist/modules/payment/grpc/index.d.ts +2 -2
  213. package/dist/modules/payment/grpc/index.js +4 -8
  214. package/dist/modules/payment/index.d.ts +2 -2
  215. package/dist/modules/payment/index.js +20 -17
  216. package/dist/modules/payment/interfaces.d.ts +3 -3
  217. package/dist/modules/payment/interfaces.js +1 -4
  218. package/dist/modules/resource/gql/federation.d.ts +1 -1
  219. package/dist/modules/resource/gql/federation.js +10 -17
  220. package/dist/modules/resource/gql/schema.d.ts +1 -1
  221. package/dist/modules/resource/gql/schema.generated.d.ts +348 -322
  222. package/dist/modules/resource/gql/schema.generated.js +28 -31
  223. package/dist/modules/resource/gql/schema.js +5 -9
  224. package/dist/modules/resource/gql/types.d.ts +2 -2
  225. package/dist/modules/resource/gql/types.js +31 -35
  226. package/dist/modules/resource/grpc/index.d.ts +13 -13
  227. package/dist/modules/resource/grpc/index.js +28 -32
  228. package/dist/modules/resource/index.d.ts +2 -2
  229. package/dist/modules/resource/index.js +20 -17
  230. package/dist/modules/resource/interfaces.d.ts +3 -3
  231. package/dist/modules/resource/interfaces.js +1 -4
  232. package/dist/modules/scheduling/gql/federation.d.ts +1 -1
  233. package/dist/modules/scheduling/gql/federation.js +10 -17
  234. package/dist/modules/scheduling/gql/schema.d.ts +1 -1
  235. package/dist/modules/scheduling/gql/schema.generated.d.ts +109 -83
  236. package/dist/modules/scheduling/gql/schema.generated.js +10 -13
  237. package/dist/modules/scheduling/gql/schema.js +5 -9
  238. package/dist/modules/scheduling/gql/types.d.ts +2 -2
  239. package/dist/modules/scheduling/gql/types.js +7 -11
  240. package/dist/modules/scheduling/grpc/index.d.ts +2 -2
  241. package/dist/modules/scheduling/grpc/index.js +4 -8
  242. package/dist/modules/scheduling/index.d.ts +2 -2
  243. package/dist/modules/scheduling/index.js +20 -17
  244. package/dist/modules/scheduling/interfaces.d.ts +3 -3
  245. package/dist/modules/scheduling/interfaces.js +1 -4
  246. package/dist/utils.d.ts +3 -3
  247. package/dist/utils.js +4 -9
  248. package/generate.ts +42 -42
  249. package/jest.config.cjs +23 -0
  250. package/package.json +18 -13
  251. package/tsconfig-base.json +8 -0
  252. package/tsconfig.debug.json +5 -1
  253. package/tsconfig.test.json +17 -2
  254. package/jest.config.js +0 -14
@@ -1,95 +1,142 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { readFile } from 'node:fs';
11
+ import path, { resolve as resolvePath } from 'node:path';
12
+ import hbs from 'handlebars';
13
+ import { marshallProtobufAny } from '../oidc/utils.js';
14
+ import * as uuid from 'uuid';
15
+ import { RegisterRequest, UserType } from '@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/user.js';
16
+ import * as jose from 'jose';
17
+ import * as url from 'node:url';
18
+ import Router from 'koa-router';
19
+ import { koaBody as bodyParser } from 'koa-body';
20
+ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
21
+ const upsertUserToken = (ids, accountId) => __awaiter(void 0, void 0, void 0, function* () {
22
+ const token = new jose.UnsecuredJWT({})
23
+ .setIssuedAt()
24
+ .setExpirationTime('30d')
25
+ .encode();
26
+ // 1 Month
27
+ const expiresIn = Date.now() + (1000 * 60 * 60 * 24 * 30);
28
+ yield ids.token.upsert({
29
+ id: uuid.v4().replace(/-/g, ''),
30
+ type: 'access_token',
31
+ expiresIn,
32
+ payload: marshallProtobufAny({
33
+ accountId,
34
+ exp: expiresIn,
35
+ jti: token
36
+ })
37
+ });
38
+ return token;
39
+ });
40
+ let layoutHbs;
41
+ export const layout = (context) => __awaiter(void 0, void 0, void 0, function* () {
42
+ if (!layoutHbs) {
43
+ const layoutTpl = yield new Promise((resolve, reject) => {
44
+ readFile(resolvePath(__dirname, 'views/layout.hbs'), (err, data) => err ? reject(err) : resolve(data.toString()));
45
+ });
46
+ layoutHbs = hbs.compile(layoutTpl);
7
47
  }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
48
+ return layoutHbs(context);
17
49
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.account = exports.login = exports.register = exports.layout = exports.createOAuth = void 0;
30
- const fs_1 = require("fs");
31
- const path_1 = require("path");
32
- const handlebars_1 = __importDefault(require("handlebars"));
33
- const utils_1 = require("../oidc/utils");
34
- const uuid = __importStar(require("uuid"));
35
- const user_1 = require("@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/user");
36
- const jose = __importStar(require("jose"));
37
- const Router = eval('require("koa-router")');
38
- let bodyParser = eval('require("koa-body")');
39
- if (typeof bodyParser !== 'function') {
40
- bodyParser = bodyParser.default;
41
- }
42
- const createOAuth = () => {
50
+ let registerHbs;
51
+ export const register = (email) => __awaiter(void 0, void 0, void 0, function* () {
52
+ if (!registerHbs) {
53
+ const registerTpl = yield new Promise((resolve, reject) => {
54
+ readFile(resolvePath(__dirname, 'views/register.hbs'), (err, data) => err ? reject(err) : resolve(data.toString()));
55
+ });
56
+ registerHbs = hbs.compile(registerTpl);
57
+ }
58
+ return layout({
59
+ title: 'Register',
60
+ body: registerHbs({ email })
61
+ });
62
+ });
63
+ let loginHbs;
64
+ export const login = (links) => __awaiter(void 0, void 0, void 0, function* () {
65
+ if (!loginHbs) {
66
+ const loginTpl = yield new Promise((resolve, reject) => {
67
+ readFile(resolvePath(__dirname, 'views/login.hbs'), (err, data) => err ? reject(err) : resolve(data.toString()));
68
+ });
69
+ loginHbs = hbs.compile(loginTpl);
70
+ }
71
+ return layout({
72
+ title: 'Login',
73
+ body: loginHbs({ links })
74
+ });
75
+ });
76
+ let accountHbs;
77
+ export const account = (user) => __awaiter(void 0, void 0, void 0, function* () {
78
+ if (!accountHbs) {
79
+ const accountTpl = yield new Promise((resolve, reject) => {
80
+ readFile(resolvePath(__dirname, 'views/account.hbs'), (err, data) => err ? reject(err) : resolve(data.toString()));
81
+ });
82
+ accountHbs = hbs.compile(accountTpl);
83
+ }
84
+ return layout({
85
+ title: 'Account',
86
+ body: accountHbs({ user })
87
+ });
88
+ });
89
+ export const createOAuth = () => {
43
90
  const router = new Router();
44
91
  router.use(bodyParser({ multipart: true }));
45
- router.get('/oauth2-login', async (ctx, next) => {
92
+ router.get('/oauth2-login', (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
46
93
  ctx.type = 'html';
47
- ctx.body = await (0, exports.login)((await ctx.identitySrvClient.oauth.GenerateLinks({})).links);
94
+ ctx.body = yield login((yield ctx.identitySrvClient.oauth.GenerateLinks({})).links);
48
95
  return next();
49
- });
50
- router.get('/oauth2-logout', async (ctx, next) => {
96
+ }));
97
+ router.get('/oauth2-logout', (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
51
98
  ctx.cookies.set('token', undefined);
52
99
  ctx.status = 303;
53
100
  ctx.redirect('/oauth2-login');
54
101
  ctx.body = 'Redirecting to login page';
55
102
  return next();
56
- });
57
- router.get('/oauth2-urls', async (ctx, next) => {
58
- ctx.body = (await ctx.identitySrvClient.oauth.GenerateLinks({})).links;
103
+ }));
104
+ router.get('/oauth2-urls', (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
105
+ ctx.body = (yield ctx.identitySrvClient.oauth.GenerateLinks({})).links;
59
106
  return next();
60
- });
61
- router.get('/oauth2-account', async (ctx, next) => {
107
+ }));
108
+ router.get('/oauth2-account', (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
62
109
  const token = ctx.cookies.get('token');
63
110
  if (!token) {
64
111
  ctx.body = 'user not logged in';
65
112
  return next();
66
113
  }
67
114
  const ids = ctx.identitySrvClient;
68
- const user = await ids.user.findByToken({
69
- token: token
115
+ const user = yield ids.user.findByToken({
116
+ token
70
117
  });
71
118
  if (!user || !user.payload) {
72
119
  ctx.body = 'user not logged in';
73
120
  return next();
74
121
  }
75
122
  ctx.type = 'html';
76
- ctx.body = await (0, exports.account)(user.payload);
123
+ ctx.body = yield account(user.payload);
77
124
  return next();
78
- });
79
- router.post('/oauth2-register', async (ctx, next) => {
125
+ }));
126
+ router.post('/oauth2-register', (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
80
127
  const ids = ctx.identitySrvClient;
81
128
  const body = ctx.request.body;
82
- const user = await ids.user.register(user_1.RegisterRequest.fromPartial({
129
+ const user = yield ids.user.register(RegisterRequest.fromPartial({
83
130
  email: body.email,
84
131
  name: body.username,
85
132
  firstName: body.first_name,
86
133
  lastName: body.last_name,
87
134
  password: body.password,
88
- userType: user_1.UserType.INDIVIDUAL_USER,
135
+ userType: UserType.INDIVIDUAL_USER,
89
136
  guest: false,
90
137
  }));
91
138
  if (user.payload) {
92
- const token = await upsertUserToken(ids, user.payload.id);
139
+ const token = yield upsertUserToken(ids, user.payload.id);
93
140
  ctx.cookies.set('token', token);
94
141
  ctx.status = 303;
95
142
  ctx.redirect('/oauth2-account');
@@ -100,17 +147,17 @@ const createOAuth = () => {
100
147
  ctx.body = user.status.message;
101
148
  }
102
149
  return next();
103
- });
104
- router.get('/oauth2/:service', async (ctx, next) => {
150
+ }));
151
+ router.get('/oauth2/:service', (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
105
152
  const ids = ctx.identitySrvClient;
106
- const user = await ids.oauth.exchangeCode({
153
+ const user = yield ids.oauth.exchangeCode({
107
154
  service: ctx.params.service,
108
155
  code: ctx.request.query['code'],
109
156
  state: ctx.request.query['state']
110
157
  });
111
158
  if (!user.user || !user.user.payload || !user.token || (user.user.status && user.user.status.code !== 200)) {
112
159
  ctx.type = 'html';
113
- ctx.body = await (0, exports.register)(user.email || '');
160
+ ctx.body = yield register(user.email || '');
114
161
  return next();
115
162
  }
116
163
  ctx.cookies.set('token', user.token.token);
@@ -118,79 +165,6 @@ const createOAuth = () => {
118
165
  ctx.redirect('/oauth2-account');
119
166
  ctx.body = 'Redirecting to account page';
120
167
  return next();
121
- });
168
+ }));
122
169
  return router;
123
170
  };
124
- exports.createOAuth = createOAuth;
125
- const upsertUserToken = async (ids, accountId) => {
126
- const token = new jose.UnsecuredJWT({})
127
- .setIssuedAt()
128
- .setExpirationTime('30d')
129
- .encode();
130
- // 1 Month
131
- const expiresIn = Date.now() + (1000 * 60 * 60 * 24 * 30);
132
- await ids.token.upsert({
133
- id: uuid.v4().replace(/-/g, ''),
134
- type: 'access_token',
135
- expiresIn: expiresIn,
136
- payload: (0, utils_1.marshallProtobufAny)({
137
- accountId: accountId,
138
- exp: expiresIn,
139
- jti: token
140
- })
141
- });
142
- return token;
143
- };
144
- let layoutHbs;
145
- const layout = async (context) => {
146
- if (!layoutHbs) {
147
- const layoutTpl = await new Promise((resolve, reject) => {
148
- (0, fs_1.readFile)((0, path_1.resolve)(__dirname, 'views/layout.hbs'), (err, data) => err ? reject(err) : resolve(data.toString()));
149
- });
150
- layoutHbs = handlebars_1.default.compile(layoutTpl);
151
- }
152
- return layoutHbs(context);
153
- };
154
- exports.layout = layout;
155
- let registerHbs;
156
- const register = async (email) => {
157
- if (!registerHbs) {
158
- const registerTpl = await new Promise((resolve, reject) => {
159
- (0, fs_1.readFile)((0, path_1.resolve)(__dirname, 'views/register.hbs'), (err, data) => err ? reject(err) : resolve(data.toString()));
160
- });
161
- registerHbs = handlebars_1.default.compile(registerTpl);
162
- }
163
- return (0, exports.layout)({
164
- title: 'Register',
165
- body: registerHbs({ email })
166
- });
167
- };
168
- exports.register = register;
169
- let loginHbs;
170
- const login = async (links) => {
171
- if (!loginHbs) {
172
- const loginTpl = await new Promise((resolve, reject) => {
173
- (0, fs_1.readFile)((0, path_1.resolve)(__dirname, 'views/login.hbs'), (err, data) => err ? reject(err) : resolve(data.toString()));
174
- });
175
- loginHbs = handlebars_1.default.compile(loginTpl);
176
- }
177
- return (0, exports.layout)({
178
- title: 'Login',
179
- body: loginHbs({ links })
180
- });
181
- };
182
- exports.login = login;
183
- let accountHbs;
184
- const account = async (user) => {
185
- if (!accountHbs) {
186
- const accountTpl = await new Promise((resolve, reject) => {
187
- (0, fs_1.readFile)((0, path_1.resolve)(__dirname, 'views/account.hbs'), (err, data) => err ? reject(err) : resolve(data.toString()));
188
- });
189
- accountHbs = handlebars_1.default.compile(accountTpl);
190
- }
191
- return (0, exports.layout)({
192
- title: 'Account',
193
- body: accountHbs({ user })
194
- });
195
- };
196
- exports.account = account;
@@ -1,4 +1,4 @@
1
- import { Logger } from 'winston';
2
- import { Adapter, AdapterConstructor } from 'oidc-provider';
3
- import { TokenServiceClient as tokenService } from "@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/token";
1
+ import { type Logger } from 'winston';
2
+ import { type Adapter, type AdapterConstructor } from 'oidc-provider';
3
+ import { type TokenServiceClient as tokenService } from '@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/token.js';
4
4
  export declare function createIdentityServiceAdapterClass(remoteTokenService: tokenService, logger: Logger, localTokenServiceFactory?: (type: string) => Adapter): AdapterConstructor;
@@ -1,116 +1,135 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createIdentityServiceAdapterClass = void 0;
4
- const utils_1 = require("./utils");
5
- const auth_1 = require("@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/auth");
6
- const in_memory_adapter_1 = require("./in-memory-adapter");
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { marshallProtobufAny, unmarshallProtobufAny } from './utils.js';
11
+ import { Subject } from '@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/auth.js';
12
+ import { InMemoryAdapter } from './in-memory-adapter.js';
7
13
  const delegateToRemoteService = (type) => ['AccessToken', 'RefreshToken'].includes(type);
8
- function createIdentityServiceAdapterClass(remoteTokenService, logger, localTokenServiceFactory) {
14
+ export function createIdentityServiceAdapterClass(remoteTokenService, logger, localTokenServiceFactory) {
9
15
  return class IdentityServiceAdapter {
10
16
  constructor(type) {
11
17
  this.type = type;
12
- this.localTokenService = localTokenServiceFactory ? localTokenServiceFactory(type) : new in_memory_adapter_1.InMemoryAdapter(type);
18
+ this.localTokenService = localTokenServiceFactory ? localTokenServiceFactory(type) : new InMemoryAdapter(type);
13
19
  }
14
- async consume(id) {
15
- logger.verbose(`Consuming ${this.type} token ${id}`);
16
- if (delegateToRemoteService(this.type)) {
17
- try {
18
- await remoteTokenService.consume({
19
- id,
20
- type: this.type,
21
- subject: undefined
22
- });
20
+ consume(id) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ logger.verbose(`Consuming ${this.type} token ${id}`);
23
+ if (delegateToRemoteService(this.type)) {
24
+ try {
25
+ yield remoteTokenService.consume({
26
+ id,
27
+ type: this.type,
28
+ subject: undefined
29
+ });
30
+ }
31
+ catch (error) {
32
+ logger.error(`Error consuming ${this.type} token ${id}`, error);
33
+ }
23
34
  }
24
- catch (error) {
25
- logger.error(`Error consuming ${this.type} token ${id}`, error);
35
+ else {
36
+ yield this.localTokenService.consume(id);
26
37
  }
27
- }
28
- else {
29
- await this.localTokenService.consume(id);
30
- }
38
+ });
31
39
  }
32
- async destroy(id) {
33
- logger.verbose(`Destroying ${this.type} token ${id}`);
34
- if (delegateToRemoteService(this.type)) {
35
- try {
36
- await remoteTokenService.destroy({
37
- id,
38
- type: this.type,
39
- subject: auth_1.Subject.fromPartial({ token: id })
40
- });
40
+ destroy(id) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ logger.verbose(`Destroying ${this.type} token ${id}`);
43
+ if (delegateToRemoteService(this.type)) {
44
+ try {
45
+ yield remoteTokenService.destroy({
46
+ id,
47
+ type: this.type,
48
+ subject: Subject.fromPartial({ token: id })
49
+ });
50
+ }
51
+ catch (error) {
52
+ logger.error(`Error destroying ${this.type} token ${id}`, error);
53
+ }
41
54
  }
42
- catch (error) {
43
- logger.error(`Error destroying ${this.type} token ${id}`, error);
55
+ else {
56
+ yield this.localTokenService.destroy(id);
44
57
  }
45
- }
46
- else {
47
- await this.localTokenService.destroy(id);
48
- }
58
+ });
49
59
  }
50
- async find(id) {
51
- logger.verbose(`Finding ${this.type} token ${id}`);
52
- if (delegateToRemoteService(this.type)) {
53
- try {
54
- let result = await remoteTokenService.find({
55
- id,
56
- type: this.type,
57
- subject: auth_1.Subject.fromPartial({ token: id })
58
- });
59
- return result ? (0, utils_1.unmarshallProtobufAny)(result) : undefined;
60
+ find(id) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ logger.verbose(`Finding ${this.type} token ${id}`);
63
+ if (delegateToRemoteService(this.type)) {
64
+ try {
65
+ let result = yield remoteTokenService.find({
66
+ id,
67
+ type: this.type,
68
+ subject: Subject.fromPartial({ token: id })
69
+ });
70
+ return result ? unmarshallProtobufAny(result) : undefined;
71
+ }
72
+ catch (error) {
73
+ logger.error(`Error finding ${this.type} token ${id}`, error);
74
+ return undefined;
75
+ }
60
76
  }
61
- catch (error) {
62
- logger.error(`Error finding ${this.type} token ${id}`, error);
63
- return undefined;
77
+ else {
78
+ return yield this.localTokenService.find(id);
64
79
  }
65
- }
66
- else {
67
- return await this.localTokenService.find(id);
68
- }
80
+ });
69
81
  }
70
- async findByUid(uid) {
71
- logger.verbose(`Finding by Uid ${uid}`);
72
- return await this.localTokenService.findByUid(uid);
82
+ findByUid(uid) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ logger.verbose(`Finding by Uid ${uid}`);
85
+ return yield this.localTokenService.findByUid(uid);
86
+ });
73
87
  }
74
88
  // Not needed. DeviceFlow only
75
- async findByUserCode(userCode) {
76
- logger.error('Finding br UserCode is unsupported', this.type, ...arguments);
77
- throw new Error('UNSUPPORTED');
89
+ findByUserCode(userCode) {
90
+ return __awaiter(this, arguments, void 0, function* () {
91
+ logger.error('Finding br UserCode is unsupported', this.type, ...arguments);
92
+ throw new Error('UNSUPPORTED');
93
+ });
78
94
  }
79
- async upsert(id, payload, expiresIn) {
80
- logger.error(`Upserting ${this.type} token ${id}`, payload);
81
- if (delegateToRemoteService(this.type)) {
82
- try {
83
- await remoteTokenService.upsert({
84
- expiresIn,
85
- id,
86
- payload: (0, utils_1.marshallProtobufAny)(payload),
87
- type: this.type,
88
- subject: undefined
89
- });
95
+ upsert(id, payload, expiresIn) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ logger.error(`Upserting ${this.type} token ${id}`, payload);
98
+ if (delegateToRemoteService(this.type)) {
99
+ try {
100
+ yield remoteTokenService.upsert({
101
+ expiresIn,
102
+ id,
103
+ payload: marshallProtobufAny(payload),
104
+ type: this.type,
105
+ subject: undefined
106
+ });
107
+ }
108
+ catch (error) {
109
+ logger.error(`Error upserting ${this.type} token ${id}`, error);
110
+ }
90
111
  }
91
- catch (error) {
92
- logger.error(`Error upserting ${this.type} token ${id}`, error);
112
+ else {
113
+ return this.localTokenService.upsert(id, payload, expiresIn * 1000);
93
114
  }
94
- }
95
- else {
96
- return this.localTokenService.upsert(id, payload, expiresIn * 1000);
97
- }
115
+ });
98
116
  }
99
- async revokeByGrantId(grantId) {
100
- logger.error(`Revoking grant id ${this.type} token ${grantId}`);
101
- await this.localTokenService.revokeByGrantId(grantId);
102
- if (delegateToRemoteService(this.type)) {
103
- try {
104
- await remoteTokenService.revokeByGrantId({
105
- grantId,
106
- subject: auth_1.Subject.fromPartial({ token: grantId })
107
- });
117
+ revokeByGrantId(grantId) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ logger.error(`Revoking grant id ${this.type} token ${grantId}`);
120
+ yield this.localTokenService.revokeByGrantId(grantId);
121
+ if (delegateToRemoteService(this.type)) {
122
+ try {
123
+ yield remoteTokenService.revokeByGrantId({
124
+ grantId,
125
+ subject: Subject.fromPartial({ token: grantId })
126
+ });
127
+ }
128
+ catch (error) {
129
+ logger.error(`Error revoking grant id ${grantId}`, error);
130
+ }
108
131
  }
109
- catch (error) {
110
- logger.error(`Error revoking grant id ${grantId}`, error);
111
- }
112
- }
132
+ });
113
133
  }
114
134
  };
115
135
  }
116
- exports.createIdentityServiceAdapterClass = createIdentityServiceAdapterClass;
@@ -1,4 +1,4 @@
1
- import { Adapter, AdapterPayload } from 'oidc-provider';
1
+ import { type Adapter, type AdapterPayload } from 'oidc-provider';
2
2
  export declare class InMemoryAdapter implements Adapter {
3
3
  private type;
4
4
  constructor(type: string);