@restorecommerce/facade 1.3.6 → 1.3.7

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 (268) hide show
  1. package/.eslintrc.cjs +1 -11
  2. package/CHANGELOG.md +12 -0
  3. package/codegen/tsconfig.codegen.tsbuildinfo +1 -0
  4. package/debug-run.ts +1 -1
  5. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  6. package/package.json +5 -4
  7. package/tsconfig-base.json +8 -19
  8. package/tsconfig.codegen.json +0 -1
  9. package/tsconfig.debug.json +1 -5
  10. package/tsconfig.generate.json +0 -3
  11. package/tsconfig.lib.json +1 -2
  12. package/tsconfig.test.json +1 -22
  13. package/codegen/index.d.ts +0 -12
  14. package/codegen/index.js +0 -43
  15. package/dist/gql/index.d.ts +0 -1
  16. package/dist/gql/index.js +0 -1
  17. package/dist/gql/protos/federation.d.ts +0 -6
  18. package/dist/gql/protos/federation.js +0 -46
  19. package/dist/gql/protos/graphql.d.ts +0 -11
  20. package/dist/gql/protos/graphql.js +0 -158
  21. package/dist/gql/protos/index.d.ts +0 -6
  22. package/dist/gql/protos/index.js +0 -6
  23. package/dist/gql/protos/registry.d.ts +0 -23
  24. package/dist/gql/protos/registry.js +0 -366
  25. package/dist/gql/protos/resolvers.d.ts +0 -9
  26. package/dist/gql/protos/resolvers.js +0 -479
  27. package/dist/gql/protos/schema.d.ts +0 -14
  28. package/dist/gql/protos/schema.js +0 -224
  29. package/dist/gql/protos/stream-to-async-iterator.d.ts +0 -50
  30. package/dist/gql/protos/stream-to-async-iterator.js +0 -190
  31. package/dist/gql/protos/types.d.ts +0 -96
  32. package/dist/gql/protos/types.js +0 -1
  33. package/dist/gql/protos/utils.d.ts +0 -18
  34. package/dist/gql/protos/utils.js +0 -133
  35. package/dist/gql/types/AccessControlTypes.d.ts +0 -6
  36. package/dist/gql/types/AccessControlTypes.js +0 -97
  37. package/dist/gql/types/DateType.d.ts +0 -2
  38. package/dist/gql/types/DateType.js +0 -29
  39. package/dist/gql/types/FilterType.d.ts +0 -2
  40. package/dist/gql/types/FilterType.js +0 -72
  41. package/dist/gql/types/MetaType.d.ts +0 -2
  42. package/dist/gql/types/MetaType.js +0 -25
  43. package/dist/gql/types/ScopeType.d.ts +0 -2
  44. package/dist/gql/types/ScopeType.js +0 -13
  45. package/dist/gql/types/SortType.d.ts +0 -3
  46. package/dist/gql/types/SortType.js +0 -30
  47. package/dist/gql/types/StatusType.d.ts +0 -2
  48. package/dist/gql/types/StatusType.js +0 -15
  49. package/dist/gql/types/index.d.ts +0 -7
  50. package/dist/gql/types/index.js +0 -7
  51. package/dist/index.d.ts +0 -66
  52. package/dist/index.js +0 -312
  53. package/dist/interfaces.d.ts +0 -54
  54. package/dist/interfaces.js +0 -6
  55. package/dist/middlewares/index.d.ts +0 -1
  56. package/dist/middlewares/index.js +0 -1
  57. package/dist/middlewares/req-res-logger/index.d.ts +0 -14
  58. package/dist/middlewares/req-res-logger/index.js +0 -90
  59. package/dist/modules/access-control/gql/federation.d.ts +0 -2
  60. package/dist/modules/access-control/gql/federation.js +0 -13
  61. package/dist/modules/access-control/gql/schema.d.ts +0 -2
  62. package/dist/modules/access-control/gql/schema.generated.d.ts +0 -1124
  63. package/dist/modules/access-control/gql/schema.generated.js +0 -80
  64. package/dist/modules/access-control/gql/schema.js +0 -5
  65. package/dist/modules/access-control/gql/types.d.ts +0 -3
  66. package/dist/modules/access-control/gql/types.js +0 -14
  67. package/dist/modules/access-control/grpc/index.d.ts +0 -13
  68. package/dist/modules/access-control/grpc/index.js +0 -14
  69. package/dist/modules/access-control/index.d.ts +0 -2
  70. package/dist/modules/access-control/index.js +0 -26
  71. package/dist/modules/access-control/interfaces.d.ts +0 -15
  72. package/dist/modules/access-control/interfaces.js +0 -1
  73. package/dist/modules/catalog/gql/federation.d.ts +0 -2
  74. package/dist/modules/catalog/gql/federation.js +0 -13
  75. package/dist/modules/catalog/gql/schema.d.ts +0 -2
  76. package/dist/modules/catalog/gql/schema.generated.d.ts +0 -1503
  77. package/dist/modules/catalog/gql/schema.generated.js +0 -74
  78. package/dist/modules/catalog/gql/schema.js +0 -5
  79. package/dist/modules/catalog/gql/types.d.ts +0 -3
  80. package/dist/modules/catalog/gql/types.js +0 -16
  81. package/dist/modules/catalog/grpc/index.d.ts +0 -15
  82. package/dist/modules/catalog/grpc/index.js +0 -16
  83. package/dist/modules/catalog/index.d.ts +0 -2
  84. package/dist/modules/catalog/index.js +0 -26
  85. package/dist/modules/catalog/interfaces.d.ts +0 -16
  86. package/dist/modules/catalog/interfaces.js +0 -1
  87. package/dist/modules/facade-status/gql/index.d.ts +0 -1
  88. package/dist/modules/facade-status/gql/index.js +0 -11
  89. package/dist/modules/facade-status/gql/resolvers.d.ts +0 -2
  90. package/dist/modules/facade-status/gql/resolvers.js +0 -18
  91. package/dist/modules/facade-status/gql/schema.d.ts +0 -3
  92. package/dist/modules/facade-status/gql/schema.generated.d.ts +0 -109
  93. package/dist/modules/facade-status/gql/schema.generated.js +0 -1
  94. package/dist/modules/facade-status/gql/schema.js +0 -14
  95. package/dist/modules/facade-status/gql/types.d.ts +0 -2
  96. package/dist/modules/facade-status/gql/types.js +0 -10
  97. package/dist/modules/facade-status/index.d.ts +0 -2
  98. package/dist/modules/facade-status/index.js +0 -8
  99. package/dist/modules/facade-status/interfaces.d.ts +0 -4
  100. package/dist/modules/facade-status/interfaces.js +0 -1
  101. package/dist/modules/fulfillment/gql/federation.d.ts +0 -2
  102. package/dist/modules/fulfillment/gql/federation.js +0 -13
  103. package/dist/modules/fulfillment/gql/schema.d.ts +0 -2
  104. package/dist/modules/fulfillment/gql/schema.generated.d.ts +0 -1539
  105. package/dist/modules/fulfillment/gql/schema.generated.js +0 -79
  106. package/dist/modules/fulfillment/gql/schema.js +0 -5
  107. package/dist/modules/fulfillment/gql/types.d.ts +0 -3
  108. package/dist/modules/fulfillment/gql/types.js +0 -12
  109. package/dist/modules/fulfillment/grpc/index.d.ts +0 -9
  110. package/dist/modules/fulfillment/grpc/index.js +0 -10
  111. package/dist/modules/fulfillment/index.d.ts +0 -2
  112. package/dist/modules/fulfillment/index.js +0 -26
  113. package/dist/modules/fulfillment/interfaces.d.ts +0 -16
  114. package/dist/modules/fulfillment/interfaces.js +0 -1
  115. package/dist/modules/identity/api-key/api-key.d.ts +0 -11
  116. package/dist/modules/identity/api-key/api-key.js +0 -137
  117. package/dist/modules/identity/gql/federation.d.ts +0 -2
  118. package/dist/modules/identity/gql/federation.js +0 -5
  119. package/dist/modules/identity/gql/schema.d.ts +0 -2
  120. package/dist/modules/identity/gql/schema.generated.d.ts +0 -1661
  121. package/dist/modules/identity/gql/schema.generated.js +0 -75
  122. package/dist/modules/identity/gql/schema.js +0 -5
  123. package/dist/modules/identity/gql/types.d.ts +0 -3
  124. package/dist/modules/identity/gql/types.js +0 -18
  125. package/dist/modules/identity/grpc/index.d.ts +0 -15
  126. package/dist/modules/identity/grpc/index.js +0 -16
  127. package/dist/modules/identity/index.d.ts +0 -4
  128. package/dist/modules/identity/index.js +0 -54
  129. package/dist/modules/identity/interfaces.d.ts +0 -22
  130. package/dist/modules/identity/interfaces.js +0 -1
  131. package/dist/modules/identity/oauth/oauth.d.ts +0 -11
  132. package/dist/modules/identity/oauth/oauth.js +0 -170
  133. package/dist/modules/identity/oidc/adapter.d.ts +0 -4
  134. package/dist/modules/identity/oidc/adapter.js +0 -135
  135. package/dist/modules/identity/oidc/in-memory-adapter.d.ts +0 -16
  136. package/dist/modules/identity/oidc/in-memory-adapter.js +0 -85
  137. package/dist/modules/identity/oidc/index.d.ts +0 -18
  138. package/dist/modules/identity/oidc/index.js +0 -147
  139. package/dist/modules/identity/oidc/interfaces.d.ts +0 -73
  140. package/dist/modules/identity/oidc/interfaces.js +0 -7
  141. package/dist/modules/identity/oidc/password-grant.d.ts +0 -2
  142. package/dist/modules/identity/oidc/password-grant.js +0 -163
  143. package/dist/modules/identity/oidc/router.d.ts +0 -13
  144. package/dist/modules/identity/oidc/router.js +0 -164
  145. package/dist/modules/identity/oidc/templates.d.ts +0 -36
  146. package/dist/modules/identity/oidc/templates.js +0 -60
  147. package/dist/modules/identity/oidc/user.d.ts +0 -6
  148. package/dist/modules/identity/oidc/user.js +0 -91
  149. package/dist/modules/identity/oidc/utils.d.ts +0 -6
  150. package/dist/modules/identity/oidc/utils.js +0 -15
  151. package/dist/modules/index.d.ts +0 -13
  152. package/dist/modules/index.js +0 -13
  153. package/dist/modules/indexing/gql/federation.d.ts +0 -2
  154. package/dist/modules/indexing/gql/federation.js +0 -13
  155. package/dist/modules/indexing/gql/schema.d.ts +0 -2
  156. package/dist/modules/indexing/gql/schema.generated.d.ts +0 -226
  157. package/dist/modules/indexing/gql/schema.generated.js +0 -6
  158. package/dist/modules/indexing/gql/schema.js +0 -5
  159. package/dist/modules/indexing/gql/types.d.ts +0 -3
  160. package/dist/modules/indexing/gql/types.js +0 -8
  161. package/dist/modules/indexing/grpc/index.d.ts +0 -7
  162. package/dist/modules/indexing/grpc/index.js +0 -8
  163. package/dist/modules/indexing/index.d.ts +0 -2
  164. package/dist/modules/indexing/index.js +0 -26
  165. package/dist/modules/indexing/interfaces.d.ts +0 -13
  166. package/dist/modules/indexing/interfaces.js +0 -1
  167. package/dist/modules/invoicing/gql/federation.d.ts +0 -2
  168. package/dist/modules/invoicing/gql/federation.js +0 -13
  169. package/dist/modules/invoicing/gql/schema.d.ts +0 -2
  170. package/dist/modules/invoicing/gql/schema.generated.d.ts +0 -1150
  171. package/dist/modules/invoicing/gql/schema.generated.js +0 -75
  172. package/dist/modules/invoicing/gql/schema.js +0 -5
  173. package/dist/modules/invoicing/gql/types.d.ts +0 -3
  174. package/dist/modules/invoicing/gql/types.js +0 -8
  175. package/dist/modules/invoicing/grpc/index.d.ts +0 -7
  176. package/dist/modules/invoicing/grpc/index.js +0 -8
  177. package/dist/modules/invoicing/index.d.ts +0 -2
  178. package/dist/modules/invoicing/index.js +0 -26
  179. package/dist/modules/invoicing/interfaces.d.ts +0 -16
  180. package/dist/modules/invoicing/interfaces.js +0 -1
  181. package/dist/modules/master_data/gql/federation.d.ts +0 -2
  182. package/dist/modules/master_data/gql/federation.js +0 -13
  183. package/dist/modules/master_data/gql/schema.d.ts +0 -2
  184. package/dist/modules/master_data/gql/schema.generated.d.ts +0 -2520
  185. package/dist/modules/master_data/gql/schema.generated.js +0 -114
  186. package/dist/modules/master_data/gql/schema.js +0 -5
  187. package/dist/modules/master_data/gql/types.d.ts +0 -3
  188. package/dist/modules/master_data/gql/types.js +0 -32
  189. package/dist/modules/master_data/grpc/index.d.ts +0 -30
  190. package/dist/modules/master_data/grpc/index.js +0 -32
  191. package/dist/modules/master_data/index.d.ts +0 -2
  192. package/dist/modules/master_data/index.js +0 -26
  193. package/dist/modules/master_data/interfaces.d.ts +0 -16
  194. package/dist/modules/master_data/interfaces.js +0 -1
  195. package/dist/modules/notification/gql/federation.d.ts +0 -2
  196. package/dist/modules/notification/gql/federation.js +0 -13
  197. package/dist/modules/notification/gql/schema.d.ts +0 -2
  198. package/dist/modules/notification/gql/schema.generated.d.ts +0 -632
  199. package/dist/modules/notification/gql/schema.generated.js +0 -68
  200. package/dist/modules/notification/gql/schema.js +0 -5
  201. package/dist/modules/notification/gql/types.d.ts +0 -3
  202. package/dist/modules/notification/gql/types.js +0 -8
  203. package/dist/modules/notification/grpc/index.d.ts +0 -7
  204. package/dist/modules/notification/grpc/index.js +0 -8
  205. package/dist/modules/notification/index.d.ts +0 -2
  206. package/dist/modules/notification/index.js +0 -26
  207. package/dist/modules/notification/interfaces.d.ts +0 -16
  208. package/dist/modules/notification/interfaces.js +0 -1
  209. package/dist/modules/ordering/gql/federation.d.ts +0 -2
  210. package/dist/modules/ordering/gql/federation.js +0 -13
  211. package/dist/modules/ordering/gql/schema.d.ts +0 -2
  212. package/dist/modules/ordering/gql/schema.generated.d.ts +0 -1407
  213. package/dist/modules/ordering/gql/schema.generated.js +0 -91
  214. package/dist/modules/ordering/gql/schema.js +0 -5
  215. package/dist/modules/ordering/gql/types.d.ts +0 -3
  216. package/dist/modules/ordering/gql/types.js +0 -8
  217. package/dist/modules/ordering/grpc/index.d.ts +0 -7
  218. package/dist/modules/ordering/grpc/index.js +0 -8
  219. package/dist/modules/ordering/index.d.ts +0 -2
  220. package/dist/modules/ordering/index.js +0 -26
  221. package/dist/modules/ordering/interfaces.d.ts +0 -16
  222. package/dist/modules/ordering/interfaces.js +0 -1
  223. package/dist/modules/ostorage/gql/federation.d.ts +0 -2
  224. package/dist/modules/ostorage/gql/federation.js +0 -13
  225. package/dist/modules/ostorage/gql/schema.d.ts +0 -2
  226. package/dist/modules/ostorage/gql/schema.generated.d.ts +0 -846
  227. package/dist/modules/ostorage/gql/schema.generated.js +0 -31
  228. package/dist/modules/ostorage/gql/schema.js +0 -5
  229. package/dist/modules/ostorage/gql/types.d.ts +0 -3
  230. package/dist/modules/ostorage/gql/types.js +0 -8
  231. package/dist/modules/ostorage/grpc/index.d.ts +0 -7
  232. package/dist/modules/ostorage/grpc/index.js +0 -8
  233. package/dist/modules/ostorage/index.d.ts +0 -2
  234. package/dist/modules/ostorage/index.js +0 -46
  235. package/dist/modules/ostorage/interfaces.d.ts +0 -16
  236. package/dist/modules/ostorage/interfaces.js +0 -1
  237. package/dist/modules/ostorage/objectDownloadReqHandler.d.ts +0 -1
  238. package/dist/modules/ostorage/objectDownloadReqHandler.js +0 -134
  239. package/dist/modules/payment/gql/federation.d.ts +0 -2
  240. package/dist/modules/payment/gql/federation.js +0 -13
  241. package/dist/modules/payment/gql/schema.d.ts +0 -2
  242. package/dist/modules/payment/gql/schema.generated.d.ts +0 -647
  243. package/dist/modules/payment/gql/schema.generated.js +0 -156
  244. package/dist/modules/payment/gql/schema.js +0 -5
  245. package/dist/modules/payment/gql/types.d.ts +0 -3
  246. package/dist/modules/payment/gql/types.js +0 -8
  247. package/dist/modules/payment/grpc/index.d.ts +0 -7
  248. package/dist/modules/payment/grpc/index.js +0 -8
  249. package/dist/modules/payment/index.d.ts +0 -2
  250. package/dist/modules/payment/index.js +0 -26
  251. package/dist/modules/payment/interfaces.d.ts +0 -16
  252. package/dist/modules/payment/interfaces.js +0 -1
  253. package/dist/modules/scheduling/gql/federation.d.ts +0 -2
  254. package/dist/modules/scheduling/gql/federation.js +0 -13
  255. package/dist/modules/scheduling/gql/schema.d.ts +0 -2
  256. package/dist/modules/scheduling/gql/schema.generated.d.ts +0 -626
  257. package/dist/modules/scheduling/gql/schema.generated.js +0 -31
  258. package/dist/modules/scheduling/gql/schema.js +0 -5
  259. package/dist/modules/scheduling/gql/types.d.ts +0 -3
  260. package/dist/modules/scheduling/gql/types.js +0 -8
  261. package/dist/modules/scheduling/grpc/index.d.ts +0 -7
  262. package/dist/modules/scheduling/grpc/index.js +0 -8
  263. package/dist/modules/scheduling/index.d.ts +0 -2
  264. package/dist/modules/scheduling/index.js +0 -26
  265. package/dist/modules/scheduling/interfaces.d.ts +0 -16
  266. package/dist/modules/scheduling/interfaces.js +0 -1
  267. package/dist/utils.d.ts +0 -5
  268. package/dist/utils.js +0 -14
@@ -1,18 +0,0 @@
1
- /// <reference types="koa-router" />
2
- import Provider from 'oidc-provider';
3
- import { type Logger } from 'winston';
4
- import { type IdentityContext } from '../interfaces.js';
5
- import type { OIDCConfig } from './interfaces.js';
6
- import { type IdentitySrvGrpcClient } from '../grpc/index.js';
7
- export type { OIDCConfig };
8
- export { createOIDCRouter, type CreateOIDCRouterArgs } from './router.js';
9
- export interface CreateOIDCArgs {
10
- logger: Logger;
11
- identitySrvClient: IdentitySrvGrpcClient;
12
- config: OIDCConfig;
13
- env: string;
14
- }
15
- export declare function createOIDC({ identitySrvClient, env, logger, config: { loginFn, post_logout_redirect_uris, localTokenServiceFactory, remoteTokenService, cookies, redirect_uris, client_id, client_secret, issuer, jwks, templates } }: CreateOIDCArgs): {
16
- provider: Provider;
17
- router: import("koa-router")<{}, IdentityContext>;
18
- };
@@ -1,147 +0,0 @@
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 Provider from 'oidc-provider';
11
- import { createOIDCRouter } from './router.js';
12
- import { createIdentityServiceAdapterClass } from './adapter.js';
13
- import { findUserById, loginUserBody, loginUserCredentials } from './user.js';
14
- import { registerPasswordGrantType } from './password-grant.js';
15
- export { createOIDCRouter } from './router.js';
16
- export function createOIDC({ identitySrvClient, env, logger, config: { loginFn, post_logout_redirect_uris, localTokenServiceFactory, remoteTokenService, cookies, redirect_uris, client_id, client_secret, issuer, jwks, templates } }) {
17
- var _a, _b;
18
- const adapterClass = createIdentityServiceAdapterClass(remoteTokenService !== null && remoteTokenService !== void 0 ? remoteTokenService : identitySrvClient.token, logger, localTokenServiceFactory);
19
- const provider = new Provider(issuer, {
20
- adapter: adapterClass,
21
- clients: [{
22
- post_logout_redirect_uris,
23
- client_id,
24
- client_secret,
25
- id_token_signed_response_alg: 'HS256',
26
- grant_types: ['refresh_token', 'authorization_code', 'password'],
27
- redirect_uris,
28
- scopes: ['openid', 'offline_access'],
29
- response_types: [
30
- 'code'
31
- ],
32
- token_endpoint_auth_method: 'client_secret_basic',
33
- }],
34
- // issueRefreshToken: async (ctx, client, code) => {
35
- // // Always issue refresh token
36
- // return client.grantTypeAllowed('refresh_token');
37
- // },
38
- jwks,
39
- ttl: {
40
- Session: (1 * 24 * 60 * 60) * 1000
41
- },
42
- cookies: {
43
- long: { signed: false },
44
- short: { signed: false },
45
- keys: cookies.keys,
46
- },
47
- // oidc-provider only looks up the accounts by their ID when it has to read the claims,
48
- // passing it our Account model method is sufficient, it should return a Promise that resolves
49
- // with an object with accountId property and a claims method.
50
- findAccount: (ctx, id) => __awaiter(this, void 0, void 0, function* () {
51
- var _c;
52
- try {
53
- const userService = (_c = ctx === null || ctx === void 0 ? void 0 : ctx.identitySrvClient) === null || _c === void 0 ? void 0 : _c.user;
54
- return {
55
- accountId: id,
56
- claims: (use, scope) => __awaiter(this, void 0, void 0, function* () {
57
- try {
58
- const user = yield findUserById(userService, id);
59
- return {
60
- sub: id,
61
- data: user
62
- };
63
- }
64
- catch (error) {
65
- logger.error('OIDC findAccount claims error', error);
66
- return {
67
- sub: id,
68
- data: {
69
- id,
70
- }
71
- };
72
- }
73
- }),
74
- };
75
- }
76
- catch (error) {
77
- logger.error('OIDC findAccount error', error);
78
- }
79
- }),
80
- claims: {
81
- acr: null,
82
- sid: null,
83
- auth_time: null,
84
- iss: null,
85
- openid: ['sub', 'data'],
86
- },
87
- responseTypes: [
88
- 'code',
89
- 'id_token',
90
- 'id_token token',
91
- 'code id_token',
92
- 'code token',
93
- 'code id_token token',
94
- 'none',
95
- ],
96
- // let's tell oidc-provider where our own interactions will be
97
- // setting a nested route is just good practice so that users
98
- // don't run into weird issues with multiple interactions open
99
- // at a time.
100
- interactions: {
101
- url: (ctx) => `/interaction/${ctx.oidc.uid}`,
102
- },
103
- features: {
104
- introspection: {
105
- enabled: true
106
- },
107
- revocation: {
108
- enabled: true
109
- },
110
- devInteractions: {
111
- // enabled: dev ?? false
112
- enabled: false
113
- },
114
- },
115
- });
116
- // Disabled due to playground being disabled
117
- // provider.use(helmet());
118
- const router = createOIDCRouter({
119
- loginFn: loginFn !== null && loginFn !== void 0 ? loginFn : loginUserBody,
120
- templates,
121
- logger,
122
- provider,
123
- env,
124
- });
125
- registerPasswordGrantType({
126
- authLogService: identitySrvClient.authentication_log,
127
- authenticate: loginUserCredentials,
128
- provider
129
- });
130
- // Disable forbidding redirect to http/localhost in dev mode
131
- if (env === 'development') {
132
- const proto = (_b = (_a = provider.Client) === null || _a === void 0 ? void 0 : _a.Schema) === null || _b === void 0 ? void 0 : _b.prototype;
133
- if (proto) {
134
- const { invalidate: orig } = proto;
135
- proto.invalidate = function invalidate(message, code) {
136
- if (code === 'implicit-force-https' || code === 'implicit-forbid-localhost') {
137
- return;
138
- }
139
- orig.call(this, message);
140
- };
141
- }
142
- }
143
- return {
144
- provider,
145
- router
146
- };
147
- }
@@ -1,73 +0,0 @@
1
- import { type Adapter, errors } from 'oidc-provider';
2
- import type Provider from 'oidc-provider';
3
- import { type IdentityContext } from '../interfaces.js';
4
- import { type AuthenticationLogServiceClient as authLogService } from '@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/authentication_log.js';
5
- import { type TokenServiceClient as tokenService } from '@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/token.js';
6
- import { type User } from '@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/user.js';
7
- export interface OIDCHbsTemplates {
8
- login?: string;
9
- layout?: string;
10
- consent?: string;
11
- }
12
- export interface OIDCConfig {
13
- remoteTokenService?: tokenService;
14
- localTokenServiceFactory?: (type: string) => Adapter;
15
- loginFn?: OIDCBodyLoginFn;
16
- issuer: string;
17
- jwks: any;
18
- client_id: string;
19
- client_secret: string;
20
- cookies: {
21
- keys: string[];
22
- };
23
- templates?: OIDCHbsTemplates;
24
- redirect_uris: string[];
25
- post_logout_redirect_uris: string[];
26
- }
27
- export interface OIDCError {
28
- key: string;
29
- message?: string;
30
- }
31
- export type UserKey = keyof User;
32
- export type AuthUserKeyWhitelist = 'id' | 'name' | 'email' | 'localeId' | 'timezoneId' | 'roleAssociations' | 'firstName' | 'lastName' | 'defaultScope' | 'tokens' | 'lastAccess';
33
- export type AuthUser = Pick<User, AuthUserKeyWhitelist>;
34
- export interface LoginFnResponse {
35
- user?: AuthUser;
36
- error?: OIDCError;
37
- identifier?: string;
38
- remember?: boolean;
39
- }
40
- export type OIDCBodyLoginFn = (ctx: IdentityContext, body: any) => Promise<LoginFnResponse>;
41
- export type OIDCBodyLoginCredentials = (ctx: IdentityContext, credentials: UserCredentials) => Promise<LoginFnResponse>;
42
- export type OIDCLoginFn = (ctx: IdentityContext, identifier?: string, password?: string, remember?: boolean) => Promise<LoginFnResponse>;
43
- export interface UserCredentials {
44
- identifier: string;
45
- password?: string;
46
- token?: string;
47
- }
48
- export interface OIDCPasswordGrantTypeConfig {
49
- provider: Provider;
50
- authenticate: OIDCBodyLoginCredentials;
51
- tokenExpiration?: number;
52
- authLogService: authLogService;
53
- }
54
- export interface TokenResponseBody {
55
- access_token?: string;
56
- id_token?: string;
57
- expires_in?: number;
58
- last_login?: number;
59
- token_type?: string;
60
- scope?: string;
61
- subject_id?: string;
62
- token_name?: string;
63
- default_scope?: string;
64
- last_access?: number;
65
- }
66
- export declare class InvalidPasswordGrant extends errors.InvalidGrant {
67
- constructor(detail: string);
68
- }
69
- export interface Claims {
70
- sub: string | undefined;
71
- data: AuthUser;
72
- [key: string]: any;
73
- }
@@ -1,7 +0,0 @@
1
- import { errors } from 'oidc-provider';
2
- export class InvalidPasswordGrant extends errors.InvalidGrant {
3
- constructor(detail) {
4
- super('invalid_password_grant');
5
- Object.assign(this, { error_description: detail, error_detail: detail });
6
- }
7
- }
@@ -1,2 +0,0 @@
1
- import { type OIDCPasswordGrantTypeConfig } from './interfaces.js';
2
- export declare const registerPasswordGrantType: (config: OIDCPasswordGrantTypeConfig) => void;
@@ -1,163 +0,0 @@
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 { InvalidPasswordGrant } from './interfaces.js';
11
- import { nanoid, epochTime } from './utils.js';
12
- import * as useragent from 'useragent';
13
- import * as uuid from 'uuid';
14
- import * as requestIp from 'request-ip';
15
- import { AuthenticationLog, AuthenticationLogList } from '@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/authentication_log.js';
16
- import { Subject } from '@restorecommerce/rc-grpc-clients/dist/generated/io/restorecommerce/auth.js';
17
- export const registerPasswordGrantType = (config) => {
18
- const performPasswordGrant = (ctx, clientId, identifier, password, key) => __awaiter(void 0, void 0, void 0, function* () {
19
- var _a, _b;
20
- const client = yield ctx.oidc.provider.Client.find(clientId);
21
- let account;
22
- try {
23
- let user = {
24
- identifier,
25
- [key]: password
26
- };
27
- account = yield config.authenticate(ctx, user);
28
- }
29
- catch (err) {
30
- if (err.details && err.details.includes(':')) {
31
- err.details = err.details.split(':')[1].trim();
32
- }
33
- throw new InvalidPasswordGrant(err.details);
34
- }
35
- if (!account || !account.user) {
36
- if (account.error && account.error.message) {
37
- throw new InvalidPasswordGrant('invalid credentials provided: ' + account.error.message);
38
- }
39
- throw new InvalidPasswordGrant('invalid credentials provided');
40
- }
41
- let expiresIn = config.tokenExpiration;
42
- if (!expiresIn) {
43
- // default value of 1 day expiration when not set in config
44
- expiresIn = 86400;
45
- }
46
- const claims = {
47
- sub: account.user.id,
48
- data: account.user
49
- };
50
- const { AccessToken } = ctx.oidc.provider;
51
- // for interactive login (to update user data in arangodb with token name)
52
- let tokenName = uuid.v4().replace(/-/g, '');
53
- claims.token_name = tokenName;
54
- let defaultScope = claims.data.defaultScope;
55
- const at = new AccessToken({
56
- gty: 'password',
57
- scope: 'openid',
58
- accountId: account.user.id,
59
- claims,
60
- client,
61
- grantId: ctx.oidc.uid,
62
- expiresWithSession: false,
63
- expiresIn
64
- });
65
- ctx.oidc.entity('AccessToken', at);
66
- const accessToken = yield at.save();
67
- let last_access;
68
- if ((_a = claims === null || claims === void 0 ? void 0 : claims.data) === null || _a === void 0 ? void 0 : _a.lastAccess) {
69
- last_access = claims.data.lastAccess;
70
- }
71
- if ((_b = claims === null || claims === void 0 ? void 0 : claims.data) === null || _b === void 0 ? void 0 : _b.tokens) {
72
- claims.data = Object.assign(Object.assign({}, claims.data), { tokens: [] });
73
- }
74
- const generateIdToken = (ctx, clientId, expiresIn, claims) => __awaiter(void 0, void 0, void 0, function* () {
75
- const client = yield ctx.oidc.provider.Client.find(clientId);
76
- ctx.oidc.entity('Client', client);
77
- const { IdToken } = ctx.oidc.provider;
78
- const jti = nanoid();
79
- const exp = epochTime() + expiresIn;
80
- const token = new IdToken(Object.assign({}, claims), { ctx });
81
- token.set('jti', jti);
82
- token.scope = 'openid profile';
83
- return yield token.issue({ expiresAt: exp });
84
- });
85
- const idToken = yield generateIdToken(ctx, clientId, expiresIn, claims);
86
- return {
87
- access_token: accessToken,
88
- id_token: idToken,
89
- expires_in: epochTime() + at.expiration,
90
- last_login: epochTime(),
91
- token_type: at.tokenType,
92
- scope: 'openid',
93
- token_name: tokenName,
94
- default_scope: defaultScope,
95
- last_access
96
- };
97
- });
98
- config.provider.registerGrantType('password', (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
99
- try {
100
- const { body, client } = ctx.oidc;
101
- ctx.type = 'json';
102
- let passwordValue;
103
- let key = 'password';
104
- if (body.password) {
105
- passwordValue = body.password;
106
- }
107
- else if (body.token) {
108
- passwordValue = body.token;
109
- key = 'token';
110
- }
111
- const req = ctx.request;
112
- let os, agentName;
113
- const agent = useragent.parse(req.headers['user-agent']);
114
- if (agent) {
115
- os = agent.os.toString();
116
- agentName = agent.toAgent();
117
- }
118
- ctx.body = yield performPasswordGrant(ctx, client.clientId, body.identifier, passwordValue, key);
119
- const token_name = ctx.body.token_name;
120
- const token = ctx.body.access_token;
121
- const scope = ctx.body.default_scope;
122
- let ipv4_address, ipv6_address;
123
- const clientIP = requestIp.getClientIp(req.req);
124
- if (clientIP && clientIP.includes('.')) {
125
- ipv4_address = clientIP;
126
- }
127
- else if (clientIP && clientIP.includes(':')) {
128
- ipv6_address = clientIP;
129
- }
130
- const authLogItem = AuthenticationLog.fromPartial({
131
- ipv4Address: ipv4_address,
132
- ipv6Address: ipv6_address,
133
- operatingSystem: os,
134
- userAgent: agentName,
135
- date: new Date().getTime(),
136
- activity: 'login',
137
- tokenName: token_name
138
- });
139
- yield config.authLogService.create(AuthenticationLogList.fromPartial({
140
- items: [authLogItem],
141
- subject: Subject.fromPartial({ token, scope })
142
- }));
143
- }
144
- catch (ex) {
145
- if (ex instanceof InvalidPasswordGrant) {
146
- ctx.status = 401;
147
- ctx.type = 'json';
148
- ctx.body = {
149
- error: ex['error'],
150
- error_description: ex['error_description']
151
- };
152
- }
153
- else {
154
- ctx.status = 400;
155
- ctx.body = {
156
- error: 'bad_request',
157
- error_description: 'Bad request'
158
- };
159
- }
160
- }
161
- yield next();
162
- }), ['identifier', 'password'], []);
163
- };
@@ -1,13 +0,0 @@
1
- import type KoaRouter from 'koa-router';
2
- import type Provider from 'oidc-provider';
3
- import { type Logger } from 'winston';
4
- import { type IdentityContext } from '../interfaces.js';
5
- import { type OIDCHbsTemplates, type OIDCBodyLoginFn } from './interfaces.js';
6
- export interface CreateOIDCRouterArgs {
7
- logger: Logger;
8
- provider: Provider;
9
- env?: string;
10
- templates?: OIDCHbsTemplates;
11
- loginFn: OIDCBodyLoginFn;
12
- }
13
- export declare const createOIDCRouter: ({ logger, loginFn, provider, env, templates }: CreateOIDCRouterArgs) => KoaRouter<{}, IdentityContext>;
@@ -1,164 +0,0 @@
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 { OIDCTemplateEngine } from './templates.js';
11
- import { koaBody } from 'koa-body';
12
- import Router from 'koa-router';
13
- export const createOIDCRouter = ({ logger, loginFn, provider, env, templates }) => {
14
- const dev = env === 'development';
15
- const tplEngine = new OIDCTemplateEngine(templates);
16
- const router = new Router();
17
- router.get('/interaction/:uid', (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
18
- const { uid, prompt, params, session, } = yield provider.interactionDetails(ctx.req, ctx.res);
19
- const client = yield provider.Client.find(params.client_id);
20
- switch (prompt.name) {
21
- case 'login': {
22
- ctx.type = 'html';
23
- ctx.body = yield tplEngine.login({
24
- title: 'Login',
25
- dev,
26
- uid,
27
- dbg: {
28
- params,
29
- prompt,
30
- session
31
- }
32
- });
33
- return;
34
- }
35
- case 'consent': {
36
- console.log('consent', prompt.details);
37
- const { prompt: { name, details } } = yield provider.interactionDetails(ctx.req, ctx.res);
38
- const consent = {};
39
- consent.rejectedScopes = [];
40
- // replace = false means previously rejected scopes and claims remain rejected
41
- // changing this to true will remove those rejections in favour of just what you rejected above
42
- consent.replace = false;
43
- const result = { consent };
44
- return provider.interactionFinished(ctx.req, ctx.res, result, {
45
- mergeWithLastSubmission: true,
46
- });
47
- // ctx.type = 'html';
48
- // ctx.body = await tplEngine.consent({
49
- // title: 'Authorize',
50
- // dev,
51
- // uid,
52
- // details: prompt.details,
53
- // dbg: {
54
- // params,
55
- // prompt,
56
- // session
57
- // }
58
- // });
59
- // return;
60
- }
61
- default:
62
- return next();
63
- }
64
- }));
65
- // router.post('/interaction/:uid/confirm', bodyParser({
66
- // text: false, json: false
67
- // }), async (ctx) => {
68
- // const { prompt: { name, details } } = await provider.interactionDetails(ctx.req, ctx.res);
69
- // const consent: any = {};
70
- // consent.rejectedScopes = [];
71
- // // replace = false means previously rejected scopes and claims remain rejected
72
- // // changing this to true will remove those rejections in favour of just what you rejected above
73
- // consent.replace = false;
74
- // const result = { consent };
75
- // return provider.interactionFinished(ctx.req, ctx.res, result, {
76
- // mergeWithLastSubmission: true,
77
- // });
78
- // });
79
- router.post('/interaction/:uid/login', koaBody({
80
- text: false, json: false
81
- }), (ctx) => __awaiter(void 0, void 0, void 0, function* () {
82
- const { prompt, uid, params, session } = yield provider.interactionDetails(ctx.req, ctx.res);
83
- if (prompt.name !== 'login') {
84
- throw new Error('INVALID_PROMPT');
85
- }
86
- const render = ({ error, identifier, remember } = {}) => __awaiter(void 0, void 0, void 0, function* () {
87
- ctx.response.type = 'html';
88
- ctx.response.body = yield tplEngine.login({
89
- title: 'Login',
90
- uid,
91
- identifier,
92
- remember,
93
- error: error !== null && error !== void 0 ? error : {
94
- key: 'ERROR',
95
- message: 'Error'
96
- },
97
- dev,
98
- dbg: {
99
- params,
100
- prompt,
101
- session
102
- }
103
- });
104
- return;
105
- });
106
- const body = typeof ctx.request.body === 'object' && ctx.request.body ? ctx.request.body : undefined;
107
- if (!body) {
108
- logger.error('OIDC login invalid body', body);
109
- return render();
110
- }
111
- const { error, user, identifier, remember } = yield loginFn(ctx, body);
112
- if (error || !user) {
113
- logger.error('OIDC login callback error', error);
114
- return render({
115
- error,
116
- identifier,
117
- remember
118
- });
119
- }
120
- if (!user) {
121
- return render({
122
- error: {
123
- key: 'INVALID_IDENTIFIER_OR_PASSWORD',
124
- message: 'Invalid identifier or password'
125
- },
126
- identifier,
127
- remember
128
- });
129
- }
130
- const result = {
131
- select_account: {},
132
- login: {
133
- remember,
134
- accountId: user.id,
135
- },
136
- meta: {}
137
- };
138
- return provider.interactionFinished(ctx.req, ctx.res, result, {
139
- mergeWithLastSubmission: false,
140
- });
141
- }));
142
- router.get('/interaction/:uid/abort', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
143
- const result = {
144
- error: 'access_denied',
145
- error_description: 'End-User aborted interaction',
146
- };
147
- return provider.interactionFinished(ctx.req, ctx.res, result, {
148
- mergeWithLastSubmission: false,
149
- });
150
- }));
151
- // router.get('/session', async (ctx) => {
152
- // const _ctx = provider.app.createContext(ctx.req, ctx.res);
153
- // // const session = await provider.Session.get(_ctx)
154
- // const x = new provider.OIDCContext(ctx)
155
- // // new provider.OIDCContext(ctx)
156
- // ctx.response.body = {
157
- // ats: x.getAccessToken(),
158
- // at: provider.AccessToken.find(x.getAccessToken()),
159
- // // session
160
- // };
161
- // });
162
- return router;
163
- };
164
- ;
@@ -1,36 +0,0 @@
1
- import { type OIDCHbsTemplates } from './interfaces.js';
2
- export interface OIDCTemplateError {
3
- key: string;
4
- message?: string;
5
- }
6
- export interface OIDCTemplateContext {
7
- title: string;
8
- error?: OIDCTemplateError;
9
- dev: boolean;
10
- dbg: {
11
- session?: any;
12
- params?: any;
13
- prompt?: any;
14
- };
15
- }
16
- export interface OIDCTemplateConsentContext extends OIDCTemplateContext {
17
- uid: string;
18
- details?: any;
19
- }
20
- export interface OIDCTemplateLoginContext extends OIDCTemplateContext {
21
- uid: string;
22
- identifier?: string;
23
- remember?: boolean;
24
- }
25
- export declare class OIDCTemplateEngine {
26
- private templates;
27
- private layoutHbs?;
28
- private loginHbs?;
29
- private consentHbs?;
30
- constructor(templates: OIDCHbsTemplates | undefined);
31
- layout(context: OIDCTemplateContext & {
32
- body: string;
33
- }): Promise<string>;
34
- login(context: OIDCTemplateLoginContext): Promise<string>;
35
- consent(context: OIDCTemplateConsentContext): Promise<string>;
36
- }