@mediaviz/sdk 0.1.0 → 1.0.60

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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/dist/sdk.cjs +21 -260
  3. package/dist/sdk.esm.js +22 -259
  4. package/dist/sdk.umd.js +21 -260
  5. package/package.json +15 -1
  6. package/MediaViz.js +0 -126
  7. package/_oauth.js +0 -3
  8. package/admin.js +0 -93
  9. package/ai_model_credits.js +0 -22
  10. package/company.js +0 -54
  11. package/curated_albums.js +0 -85
  12. package/custom_albums.js +0 -78
  13. package/email_tokens.js +0 -64
  14. package/errors.js +0 -81
  15. package/health.js +0 -20
  16. package/index.js +0 -21
  17. package/keywords.js +0 -123
  18. package/oauth/.prettierrc +0 -6
  19. package/oauth/README.md +0 -76
  20. package/oauth/browser-smoke-test.html +0 -45
  21. package/oauth/implementation_plan.json +0 -106
  22. package/oauth/package-lock.json +0 -5236
  23. package/oauth/package.json +0 -28
  24. package/oauth/rollup.config.js +0 -21
  25. package/oauth/smoke-test.js +0 -27
  26. package/oauth/spec.md +0 -187
  27. package/oauth/src/__tests__/browser-smoke-test.test.js +0 -38
  28. package/oauth/src/__tests__/client.test.js +0 -556
  29. package/oauth/src/__tests__/errors.test.js +0 -73
  30. package/oauth/src/__tests__/http.test.js +0 -102
  31. package/oauth/src/__tests__/index.test.js +0 -53
  32. package/oauth/src/__tests__/package-fields.test.js +0 -29
  33. package/oauth/src/__tests__/pkce.test.js +0 -55
  34. package/oauth/src/__tests__/rollup-build.test.js +0 -58
  35. package/oauth/src/__tests__/smoke-test.test.js +0 -26
  36. package/oauth/src/__tests__/types.test.js +0 -29
  37. package/oauth/src/client.js +0 -180
  38. package/oauth/src/errors.js +0 -32
  39. package/oauth/src/http.js +0 -52
  40. package/oauth/src/index.js +0 -7
  41. package/oauth/src/pkce.js +0 -50
  42. package/oauth/src/types.js +0 -67
  43. package/oauth_authorization.js +0 -53
  44. package/oauth_clients.js +0 -18
  45. package/oauth_login.js +0 -24
  46. package/oauth_token.js +0 -30
  47. package/person.js +0 -54
  48. package/photos.js +0 -106
  49. package/photoupload.js +0 -55
  50. package/projects.js +0 -191
  51. package/rollup.config.js +0 -12
  52. package/search.js +0 -99
  53. package/users.js +0 -137
@@ -1,28 +0,0 @@
1
- {
2
- "name": "@yourorg/oauth-sdk",
3
- "version": "0.1.0",
4
- "description": "OAuth 2.0 Authorization Code + PKCE client SDK for confidential server-side clients",
5
- "main": "src/index.js",
6
- "module": "dist/oauth-sdk.esm.js",
7
- "browser": "dist/oauth-sdk.umd.js",
8
- "files": ["src/", "dist/"],
9
- "scripts": {
10
- "build": "rollup -c",
11
- "prepublishOnly": "npm run build",
12
- "test": "jest",
13
- "lint": "eslint src/"
14
- },
15
- "devDependencies": {
16
- "@rollup/plugin-commonjs": "^29.0.2",
17
- "@rollup/plugin-node-resolve": "^16.0.3",
18
- "@rollup/plugin-terser": "^1.0.0",
19
- "eslint": "^8.57.0",
20
- "jest": "^29.7.0",
21
- "prettier": "^3.2.5",
22
- "rollup": "^4.59.0"
23
- },
24
- "engines": {
25
- "node": ">=18"
26
- },
27
- "license": "MIT"
28
- }
@@ -1,21 +0,0 @@
1
- import nodeResolve from '@rollup/plugin-node-resolve';
2
- import commonjs from '@rollup/plugin-commonjs';
3
- import terser from '@rollup/plugin-terser';
4
-
5
- export default {
6
- input: 'src/index.js',
7
- output: [
8
- {
9
- file: 'dist/oauth-sdk.umd.js',
10
- format: 'umd',
11
- name: 'OAuthSDK',
12
- exports: 'named',
13
- plugins: [terser()],
14
- },
15
- {
16
- file: 'dist/oauth-sdk.esm.js',
17
- format: 'esm',
18
- },
19
- ],
20
- plugins: [nodeResolve(), commonjs()],
21
- };
@@ -1,27 +0,0 @@
1
- 'use strict';
2
-
3
- const { OAuthClient } = require('./src/index');
4
-
5
- const client = new OAuthClient({
6
- baseUrl: 'https://example.com',
7
- clientId: 'test-client-id',
8
- clientSecret: 'test-client-secret',
9
- redirectUri: 'https://example.com/callback',
10
- });
11
-
12
- function assert(condition, message) {
13
- if (!condition) {
14
- console.error(`FAIL: ${message}`);
15
- process.exit(1);
16
- }
17
- }
18
-
19
- (async () => {
20
- const result = await client.generateAuthorizationUrl();
21
-
22
- assert(result.url.includes('response_type=code'), `url must contain 'response_type=code', got: ${result.url}`);
23
- assert(result.code_verifier.length === 64, `code_verifier must be 64 chars, got: ${result.code_verifier.length}`);
24
- assert(result.state.length === 32, `state must be 32 chars, got: ${result.state.length}`);
25
-
26
- console.log('OK');
27
- })();
package/oauth/spec.md DELETED
@@ -1,187 +0,0 @@
1
- # JavaScript SDK Spec
2
-
3
- ## Overview
4
-
5
- OAuth 2.0 client SDK targeting both browsers and Node.js (>=18). Implements the Authorization Code flow with PKCE (RFC 7636). No runtime dependencies.
6
-
7
- ---
8
-
9
- ## Module Outputs
10
-
11
- | File | Format | Use case |
12
- |---|---|---|
13
- | `src/index.js` | CJS (`require`) | Node.js |
14
- | `dist/oauth-sdk.umd.js` | UMD (minified) | `<script>` tag, AMD loaders |
15
- | `dist/oauth-sdk.esm.js` | ESM | Bundler (`import`) |
16
-
17
- `dist/` is produced by `npm run build` and excluded from version control.
18
-
19
- ### Browser `<script>` usage
20
-
21
- ```html
22
- <script src="dist/oauth-sdk.umd.js"></script>
23
- <script>
24
- const { OAuthClient } = OAuthSDK;
25
- const client = new OAuthClient({ ... });
26
- </script>
27
- ```
28
-
29
- ### ESM usage
30
-
31
- ```js
32
- import { OAuthClient } from '@yourorg/oauth-sdk/dist/oauth-sdk.esm.js';
33
- ```
34
-
35
- ---
36
-
37
- ## Public API
38
-
39
- ### `new OAuthClient(config)`
40
-
41
- | Field | Type | Description |
42
- |---|---|---|
43
- | `config.baseUrl` | `string` | Base URL of the OAuth server |
44
- | `config.clientId` | `string` | Registered client_id |
45
- | `config.clientSecret` | `string` | Registered client_secret |
46
- | `config.redirectUri` | `string` | Registered redirect URI |
47
-
48
- ### Methods
49
-
50
- ```js
51
- // Start the auth flow; persist state and code_verifier across the redirect
52
- async generateAuthorizationUrl(state?: string): Promise<AuthorizationUrlResult>
53
-
54
- // Exchange the auth code returned by the server for tokens
55
- async exchangeCode(code, codeVerifier, redirectUri?: string): Promise<TokenResponse>
56
-
57
- // Get a fresh access token using a refresh token
58
- async refreshAccessToken(refreshToken): Promise<TokenResponse>
59
-
60
- // Revoke a token (access or refresh)
61
- async revokeToken(token, tokenTypeHint?: string): Promise<void>
62
-
63
- // Authenticated fetch with automatic 401-intercept-and-refresh
64
- async request(url, method, accessToken, refreshToken, body?: object): Promise<AuthenticatedResponse>
65
-
66
- // Decode JWT payload without signature verification
67
- decodeAccessToken(accessToken): TokenPayload
68
- ```
69
-
70
- ### Types
71
-
72
- **`AuthorizationUrlResult`**
73
-
74
- | Field | Type | Notes |
75
- |---|---|---|
76
- | `url` | `string` | Full authorization URL |
77
- | `state` | `string` | CSRF state; persist until callback |
78
- | `code_verifier` | `string` | PKCE verifier; persist until callback |
79
-
80
- **`TokenResponse`**
81
-
82
- | Field | Type | Notes |
83
- |---|---|---|
84
- | `access_token` | `string` | Signed JWT |
85
- | `token_type` | `string` | Always `"bearer"` |
86
- | `expires_in` | `number` | Seconds until expiry |
87
- | `refresh_token` | `string` | Opaque refresh token |
88
-
89
- **`TokenPayload`** (decoded JWT)
90
-
91
- | Field | Type |
92
- |---|---|
93
- | `user_id` | `string` |
94
- | `client_id` | `string` |
95
- | `jti` | `string` |
96
- | `iat` | `number` |
97
- | `exp` | `number` |
98
-
99
- **`AuthenticatedResponse`**
100
-
101
- | Field | Type | Notes |
102
- |---|---|---|
103
- | `data` | `object` | Parsed JSON from resource server |
104
- | `updatedTokens` | `TokenResponse \| null` | Non-null only when refresh occurred |
105
-
106
- ### `OAuthError`
107
-
108
- Extends `Error`. Thrown on all OAuth and HTTP errors.
109
-
110
- | Property | Type |
111
- |---|---|
112
- | `code` | `string` (RFC 6749 error code) |
113
- | `description` | `string` |
114
- | `httpStatus` | `number` |
115
-
116
- ### `OAuthErrorCode`
117
-
118
- Frozen object with RFC 6749 error code constants:
119
-
120
- ```
121
- INVALID_REQUEST, INVALID_CLIENT, INVALID_GRANT, UNAUTHORIZED_CLIENT,
122
- UNSUPPORTED_GRANT_TYPE, ACCESS_DENIED, SERVER_ERROR
123
- ```
124
-
125
- ---
126
-
127
- ## Crypto
128
-
129
- All cryptographic operations use `globalThis.crypto` (Web Crypto API). No Node.js built-ins.
130
-
131
- - `generateCodeVerifier()` — 64-char base64url string from 48 random bytes via `crypto.getRandomValues`
132
- - `generateCodeChallenge(verifier)` — `async`; returns `Base64URL(SHA-256(verifier))` via `crypto.subtle.digest`
133
- - `generateState()` — 32-char lowercase hex from 16 random bytes via `crypto.getRandomValues`
134
-
135
- `crypto.subtle` is async, which is why `generateAuthorizationUrl` is also async.
136
-
137
- ---
138
-
139
- ## Build
140
-
141
- ```sh
142
- npm run build # produces dist/oauth-sdk.umd.js and dist/oauth-sdk.esm.js
143
- npm run prepublishOnly # runs build automatically before npm publish
144
- ```
145
-
146
- Rollup config (`rollup.config.js`):
147
- - Input: `src/index.js`
148
- - UMD output: minified via `@rollup/plugin-terser`, global name `OAuthSDK`
149
- - ESM output: unminified
150
- - Plugins: `@rollup/plugin-node-resolve`, `@rollup/plugin-commonjs`
151
-
152
- ---
153
-
154
- ## Testing
155
-
156
- ```sh
157
- npm test # runs Jest
158
- ```
159
-
160
- | Test file | Covers |
161
- |---|---|
162
- | `client.test.js` | All `OAuthClient` methods, 401-retry flow, JWT decode |
163
- | `pkce.test.js` | RFC 7636 test vector, verifier/challenge/state generation |
164
- | `errors.test.js` | `OAuthError` constructor, `fromResponse` parsing |
165
- | `http.test.js` | `postForm`, `getJson`, error propagation |
166
- | `index.test.js` | Barrel exports, `OAuthErrorCode` completeness |
167
- | `types.test.js` | `OAuthErrorCode` values and immutability |
168
- | `rollup-build.test.js` | Dist files exist, UMD is minified, no `require('crypto')` in bundle |
169
- | `package-fields.test.js` | `main`, `module`, `browser`, `files`, build scripts present |
170
- | `smoke-test.test.js` | `node smoke-test.js` exits 0 |
171
- | `browser-smoke-test.test.js` | `browser-smoke-test.html` references UMD bundle and `OAuthSDK` global |
172
-
173
- `browser-smoke-test.html` loads the UMD bundle via `<script>` and calls `generateAuthorizationUrl` to verify the bundle works end-to-end in a browser context.
174
-
175
- ---
176
-
177
- ## Constraints
178
-
179
- - No runtime dependencies
180
- - Plain JS — no TypeScript compilation, no Babel
181
- - ES2020+ only — no IE11, no polyfills
182
- - Node.js >=18 required (Web Crypto API availability)
183
- - Public API surface (`OAuthClient`, `OAuthError`, `OAuthErrorCode`) is stable
184
-
185
- ## Browser Compatibility
186
-
187
- Chrome 80+, Firefox 75+, Safari 13.1+, Edge 80+
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
-
6
- const htmlPath = path.resolve(__dirname, '../../browser-smoke-test.html');
7
-
8
- describe('browser-smoke-test.html', () => {
9
- let html;
10
-
11
- beforeAll(() => {
12
- html = fs.readFileSync(htmlPath, 'utf8');
13
- });
14
-
15
- test('file exists', () => {
16
- expect(fs.existsSync(htmlPath)).toBe(true);
17
- });
18
-
19
- test('loads dist/oauth-sdk.umd.js via script tag', () => {
20
- expect(html).toContain('src="dist/oauth-sdk.umd.js"');
21
- });
22
-
23
- test('references OAuthSDK global', () => {
24
- expect(html).toContain('OAuthSDK');
25
- });
26
-
27
- test('awaits generateAuthorizationUrl', () => {
28
- expect(html).toContain('await client.generateAuthorizationUrl()');
29
- });
30
-
31
- test('asserts response_type=code in url', () => {
32
- expect(html).toContain('response_type=code');
33
- });
34
-
35
- test('logs PASS on success', () => {
36
- expect(html).toContain('PASS');
37
- });
38
- });