@oxyhq/core 21.0.0 → 21.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/HttpService.js +47 -8
- package/dist/cjs/i18n/locales/en-US.json +7 -2
- package/dist/cjs/i18n/locales/es-ES.json +7 -2
- package/dist/cjs/i18n/locales/locales/en-US.json +7 -2
- package/dist/cjs/i18n/locales/locales/es-ES.json +7 -2
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/inference/OxyInferenceClient.js +330 -0
- package/dist/cjs/mixins/OxyServices.accounts.js +5 -72
- package/dist/cjs/mixins/OxyServices.inference.js +59 -0
- package/dist/cjs/mixins/OxyServices.utility.js +18 -6
- package/dist/cjs/mixins/index.js +6 -0
- package/dist/cjs/server/auth.js +76 -0
- package/dist/cjs/server/cors.js +84 -15
- package/dist/cjs/server/index.js +5 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/HttpService.js +47 -8
- package/dist/esm/i18n/locales/en-US.json +7 -2
- package/dist/esm/i18n/locales/es-ES.json +7 -2
- package/dist/esm/i18n/locales/locales/en-US.json +7 -2
- package/dist/esm/i18n/locales/locales/es-ES.json +7 -2
- package/dist/esm/index.js +4 -0
- package/dist/esm/inference/OxyInferenceClient.js +325 -0
- package/dist/esm/mixins/OxyServices.accounts.js +5 -72
- package/dist/esm/mixins/OxyServices.inference.js +56 -0
- package/dist/esm/mixins/OxyServices.utility.js +18 -6
- package/dist/esm/mixins/index.js +6 -0
- package/dist/esm/server/auth.js +72 -0
- package/dist/esm/server/cors.js +82 -15
- package/dist/esm/server/index.js +1 -1
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/HttpService.d.ts +39 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/inference/OxyInferenceClient.d.ts +324 -0
- package/dist/types/mixins/OxyServices.accounts.d.ts +73 -95
- package/dist/types/mixins/OxyServices.inference.d.ts +95 -0
- package/dist/types/mixins/OxyServices.utility.d.ts +44 -13
- package/dist/types/mixins/index.d.ts +2 -1
- package/dist/types/server/auth.d.ts +80 -0
- package/dist/types/server/cors.d.ts +41 -0
- package/dist/types/server/index.d.ts +2 -2
- package/package.json +2 -2
- package/src/HttpService.ts +50 -10
- package/src/__tests__/httpServiceUnwrapEnvelope.test.ts +115 -0
- package/src/i18n/locales/en-US.json +7 -2
- package/src/i18n/locales/es-ES.json +7 -2
- package/src/index.ts +19 -7
- package/src/inference/OxyInferenceClient.ts +590 -0
- package/src/inference/__tests__/OxyInferenceClient.test.ts +383 -0
- package/src/mixins/OxyServices.accounts.ts +75 -176
- package/src/mixins/OxyServices.inference.ts +57 -0
- package/src/mixins/OxyServices.utility.ts +58 -14
- package/src/mixins/__tests__/accounts.test.ts +57 -102
- package/src/mixins/__tests__/inferenceFactory.test.ts +58 -0
- package/src/mixins/__tests__/serviceAuth.test.ts +2 -0
- package/src/mixins/index.ts +8 -0
- package/src/server/__tests__/cors.socket.test.ts +225 -0
- package/src/server/__tests__/serviceTokenAttribution.test.ts +396 -0
- package/src/server/auth.ts +118 -0
- package/src/server/cors.ts +87 -12
- package/src/server/index.ts +6 -0
- package/src/session/__tests__/accountDialogShape.test.ts +118 -0
package/src/server/index.ts
CHANGED
|
@@ -18,7 +18,11 @@
|
|
|
18
18
|
export {
|
|
19
19
|
createOptionalOxyAuth,
|
|
20
20
|
createOxyAuthMiddleware,
|
|
21
|
+
getOxyBillingPrincipal,
|
|
22
|
+
getOxyDelegatedUserId,
|
|
23
|
+
getOxyRequestAttribution,
|
|
21
24
|
getOxyUserId,
|
|
25
|
+
getRequiredOxyBillingPrincipal,
|
|
22
26
|
getRequiredOxyUserId,
|
|
23
27
|
isOxyAuthenticated,
|
|
24
28
|
requireOxyAuth,
|
|
@@ -28,6 +32,8 @@ export type {
|
|
|
28
32
|
OxyAuthenticatedRequest,
|
|
29
33
|
OxyAuthMiddlewareOptions,
|
|
30
34
|
OxyAuthRequest,
|
|
35
|
+
OxyBillingPrincipal,
|
|
36
|
+
OxyRequestAttribution,
|
|
31
37
|
OxyRequestUser,
|
|
32
38
|
OxyServiceActingAsContext,
|
|
33
39
|
OxyServiceAppContext,
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two halves of the retired flat account list that a text scan cannot prove
|
|
3
|
+
* gone.
|
|
4
|
+
*
|
|
5
|
+
* `scripts/validate-no-flat-account-list.mjs` bans the identifiers that left the
|
|
6
|
+
* packages outright — `SwitchableAccount`, `projectSwitchableAccounts`,
|
|
7
|
+
* `useSwitchableAccounts`, `useAccountStore` and the rest — because each of
|
|
8
|
+
* those names is unique enough that a match is always a reintroduction. Two
|
|
9
|
+
* pieces of the same removal are NOT: an `accounts` field on the snapshot and a
|
|
10
|
+
* `switchTo` method on the controller are ordinary words. `'accounts'` is a live
|
|
11
|
+
* VIEW name three lines away in the same file, so a scoped grep there would fire
|
|
12
|
+
* on the thing that is supposed to be there.
|
|
13
|
+
*
|
|
14
|
+
* ## Why this is a RUNTIME check and not a type-level one
|
|
15
|
+
*
|
|
16
|
+
* A `type Has<S, K> = K extends keyof S ? true : false` assertion reads better
|
|
17
|
+
* and is checked by nothing here. `packages/core/tsconfig*.json` all carry
|
|
18
|
+
* `"exclude": ["**\/__tests__"]`, so `tsc` never sees a test file, and
|
|
19
|
+
* `jest.config.js` sets `diagnostics: false`, so ts-jest transpiles without
|
|
20
|
+
* typechecking. That version was written first and MUTATION-TESTED: putting
|
|
21
|
+
* `accounts: string[]` back on the interface and `switchTo()` back on the class
|
|
22
|
+
* left both assertions green. It is recorded here because the type-level form is
|
|
23
|
+
* the obvious thing to reach for, and it cannot fail in this package.
|
|
24
|
+
*
|
|
25
|
+
* The residual gap of the runtime form is an OPTIONAL field nobody writes —
|
|
26
|
+
* `accounts?: SwitchableAccount[]` would satisfy `tsc` without appearing on a
|
|
27
|
+
* snapshot. A REQUIRED one cannot hide: `computeSnapshot()` is strict, so the
|
|
28
|
+
* field has to be populated, and then it is here. An optional list nothing
|
|
29
|
+
* writes is not the mechanism coming back.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import type { DeviceSessionState } from '@oxyhq/contracts';
|
|
33
|
+
import type { OxyServices } from '../../OxyServices';
|
|
34
|
+
import { SessionClient, type SessionClientHost } from '../SessionClient';
|
|
35
|
+
import { createAccountDialogController } from '../accountDialogController';
|
|
36
|
+
|
|
37
|
+
const host: SessionClientHost = {
|
|
38
|
+
makeRequest: jest.fn(async () => undefined),
|
|
39
|
+
getBaseURL: () => 'http://test.invalid',
|
|
40
|
+
getAccessToken: () => null,
|
|
41
|
+
getDeviceCredential: () => null,
|
|
42
|
+
onTokensChanged: () => () => undefined,
|
|
43
|
+
setTokens: jest.fn(),
|
|
44
|
+
getCurrentAccountId: () => null,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const oxyServices = {
|
|
48
|
+
getAccessToken: jest.fn(() => null),
|
|
49
|
+
getBaseURL: jest.fn(() => 'http://test.invalid'),
|
|
50
|
+
onTokensChanged: jest.fn(() => () => undefined),
|
|
51
|
+
getFileDownloadUrl: jest.fn((id: string) => `https://cdn/${id}`),
|
|
52
|
+
} as unknown as OxyServices;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Every key the snapshot carries, and the whole set of them.
|
|
56
|
+
*
|
|
57
|
+
* An exact set rather than `not.toContain('accounts')` on purpose: it fails on
|
|
58
|
+
* ANY new field, not only on one spelled the way the old one was. The snapshot
|
|
59
|
+
* is a published contract that four surfaces render from, so growing it should
|
|
60
|
+
* be a deliberate edit here — and a flat list would come back under a new name
|
|
61
|
+
* (`rows`, `switchable`, `entries`) at least as readily as under the old one,
|
|
62
|
+
* which a name-specific check would wave through.
|
|
63
|
+
*/
|
|
64
|
+
const SNAPSHOT_KEYS = [
|
|
65
|
+
'activatingContextId',
|
|
66
|
+
'activeContext',
|
|
67
|
+
'commonsAvailability',
|
|
68
|
+
'directory',
|
|
69
|
+
'error',
|
|
70
|
+
'loading',
|
|
71
|
+
'removingContextId',
|
|
72
|
+
'removingPrincipalId',
|
|
73
|
+
'signIn',
|
|
74
|
+
'view',
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
describe('the account dialog surface after the flat list was retired', () => {
|
|
78
|
+
it('carries the server directory, and no flat account list beside it', () => {
|
|
79
|
+
const controller = createAccountDialogController({
|
|
80
|
+
oxyServices,
|
|
81
|
+
sessionClient: new SessionClient(host),
|
|
82
|
+
clientId: 'oxy_dk_test',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const snapshot = controller.getSnapshot();
|
|
86
|
+
|
|
87
|
+
// The absence half. `accounts` was the deduped union of the device's
|
|
88
|
+
// sign-ins and the CALLER's account graph — and a client holds one caller's
|
|
89
|
+
// graph and cannot enumerate another principal's, so on a device holding two
|
|
90
|
+
// people it answered with one person's accounts as though they were the
|
|
91
|
+
// device's.
|
|
92
|
+
expect(Object.keys(snapshot).sort()).toEqual(SNAPSHOT_KEYS);
|
|
93
|
+
|
|
94
|
+
// The positive control, in the same assertion and again here: a snapshot
|
|
95
|
+
// that stopped being built at all would satisfy "has no `accounts`" too.
|
|
96
|
+
expect(snapshot).toHaveProperty('directory');
|
|
97
|
+
expect(snapshot).toHaveProperty('activeContext');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('switches on a context pair, and offers no account-id switch', () => {
|
|
101
|
+
const controller = createAccountDialogController({
|
|
102
|
+
oxyServices,
|
|
103
|
+
sessionClient: new SessionClient(host),
|
|
104
|
+
clientId: 'oxy_dk_test',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// `switchTo(accountId)` could not express WHICH person's route into a shared
|
|
108
|
+
// organization was being taken, so on a device where two people both reach
|
|
109
|
+
// one org it chose for the user. `activateContext(contextId)` names the
|
|
110
|
+
// pair, and `signOutContext` / `signOutPrincipal` are the two removals an
|
|
111
|
+
// account id likewise cannot name.
|
|
112
|
+
expect('switchTo' in controller).toBe(false);
|
|
113
|
+
|
|
114
|
+
expect(typeof controller.activateContext).toBe('function');
|
|
115
|
+
expect(typeof controller.signOutContext).toBe('function');
|
|
116
|
+
expect(typeof controller.signOutPrincipal).toBe('function');
|
|
117
|
+
});
|
|
118
|
+
});
|