@markwharton/pwa-core 1.8.0 → 2.0.0
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/{client/api.d.ts → client.d.ts} +85 -9
- package/dist/{client/api.js → client.js} +159 -56
- package/dist/index.d.ts +10 -2
- package/dist/index.js +14 -6
- package/dist/server.d.ts +283 -0
- package/dist/server.js +476 -0
- package/dist/shared.d.ts +150 -0
- package/dist/shared.js +124 -0
- package/package.json +11 -12
- package/dist/__tests__/auth/apiKey.test.d.ts +0 -1
- package/dist/__tests__/auth/apiKey.test.js +0 -80
- package/dist/__tests__/auth/token.test.d.ts +0 -1
- package/dist/__tests__/auth/token.test.js +0 -212
- package/dist/__tests__/auth/types.test.d.ts +0 -1
- package/dist/__tests__/auth/types.test.js +0 -77
- package/dist/__tests__/client/api.test.d.ts +0 -1
- package/dist/__tests__/client/api.test.js +0 -369
- package/dist/__tests__/client/apiError.test.d.ts +0 -1
- package/dist/__tests__/client/apiError.test.js +0 -91
- package/dist/__tests__/http/responses.test.d.ts +0 -1
- package/dist/__tests__/http/responses.test.js +0 -112
- package/dist/__tests__/http/status.test.d.ts +0 -1
- package/dist/__tests__/http/status.test.js +0 -27
- package/dist/__tests__/server/auth/apiKey.test.d.ts +0 -1
- package/dist/__tests__/server/auth/apiKey.test.js +0 -80
- package/dist/__tests__/server/auth/token.test.d.ts +0 -1
- package/dist/__tests__/server/auth/token.test.js +0 -299
- package/dist/__tests__/server/http/responses.test.d.ts +0 -1
- package/dist/__tests__/server/http/responses.test.js +0 -112
- package/dist/__tests__/server/storage/client.test.d.ts +0 -1
- package/dist/__tests__/server/storage/client.test.js +0 -173
- package/dist/__tests__/server/storage/keys.test.d.ts +0 -1
- package/dist/__tests__/server/storage/keys.test.js +0 -47
- package/dist/__tests__/shared/auth/types.test.d.ts +0 -1
- package/dist/__tests__/shared/auth/types.test.js +0 -77
- package/dist/__tests__/shared/http/status.test.d.ts +0 -1
- package/dist/__tests__/shared/http/status.test.js +0 -29
- package/dist/__tests__/storage/client.test.d.ts +0 -1
- package/dist/__tests__/storage/client.test.js +0 -173
- package/dist/__tests__/storage/keys.test.d.ts +0 -1
- package/dist/__tests__/storage/keys.test.js +0 -47
- package/dist/__tests__/types.test.d.ts +0 -1
- package/dist/__tests__/types.test.js +0 -56
- package/dist/auth/apiKey.d.ts +0 -44
- package/dist/auth/apiKey.js +0 -59
- package/dist/auth/index.d.ts +0 -3
- package/dist/auth/index.js +0 -22
- package/dist/auth/token.d.ts +0 -56
- package/dist/auth/token.js +0 -104
- package/dist/auth/types.d.ts +0 -63
- package/dist/auth/types.js +0 -41
- package/dist/client/apiError.d.ts +0 -48
- package/dist/client/apiError.js +0 -65
- package/dist/client/index.d.ts +0 -3
- package/dist/client/index.js +0 -14
- package/dist/client/types.d.ts +0 -12
- package/dist/client/types.js +0 -5
- package/dist/http/index.d.ts +0 -3
- package/dist/http/index.js +0 -14
- package/dist/http/responses.d.ts +0 -82
- package/dist/http/responses.js +0 -132
- package/dist/http/status.d.ts +0 -17
- package/dist/http/status.js +0 -19
- package/dist/http/types.d.ts +0 -10
- package/dist/http/types.js +0 -5
- package/dist/server/auth/apiKey.d.ts +0 -44
- package/dist/server/auth/apiKey.js +0 -59
- package/dist/server/auth/index.d.ts +0 -3
- package/dist/server/auth/index.js +0 -19
- package/dist/server/auth/token.d.ts +0 -102
- package/dist/server/auth/token.js +0 -158
- package/dist/server/http/index.d.ts +0 -1
- package/dist/server/http/index.js +0 -12
- package/dist/server/http/responses.d.ts +0 -82
- package/dist/server/http/responses.js +0 -132
- package/dist/server/index.d.ts +0 -4
- package/dist/server/index.js +0 -37
- package/dist/server/storage/client.d.ts +0 -48
- package/dist/server/storage/client.js +0 -107
- package/dist/server/storage/index.d.ts +0 -2
- package/dist/server/storage/index.js +0 -11
- package/dist/server/storage/keys.d.ts +0 -8
- package/dist/server/storage/keys.js +0 -14
- package/dist/shared/auth/index.d.ts +0 -2
- package/dist/shared/auth/index.js +0 -7
- package/dist/shared/auth/types.d.ts +0 -63
- package/dist/shared/auth/types.js +0 -41
- package/dist/shared/http/index.d.ts +0 -3
- package/dist/shared/http/index.js +0 -5
- package/dist/shared/http/status.d.ts +0 -19
- package/dist/shared/http/status.js +0 -21
- package/dist/shared/http/types.d.ts +0 -10
- package/dist/shared/http/types.js +0 -5
- package/dist/shared/index.d.ts +0 -5
- package/dist/shared/index.js +0 -10
- package/dist/storage/client.d.ts +0 -48
- package/dist/storage/client.js +0 -107
- package/dist/storage/index.d.ts +0 -2
- package/dist/storage/index.js +0 -11
- package/dist/storage/keys.d.ts +0 -8
- package/dist/storage/keys.js +0 -14
- package/dist/types.d.ts +0 -48
- package/dist/types.js +0 -41
package/dist/storage/client.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initStorage = initStorage;
|
|
4
|
-
exports.initStorageFromEnv = initStorageFromEnv;
|
|
5
|
-
exports.useManagedIdentity = useManagedIdentity;
|
|
6
|
-
exports.getTableClient = getTableClient;
|
|
7
|
-
exports.clearTableClientCache = clearTableClientCache;
|
|
8
|
-
const data_tables_1 = require("@azure/data-tables");
|
|
9
|
-
const identity_1 = require("@azure/identity");
|
|
10
|
-
/**
|
|
11
|
-
* Azure Table Storage client factory with managed identity support
|
|
12
|
-
*/
|
|
13
|
-
// Cache table clients to avoid repeated connections
|
|
14
|
-
const tableClients = new Map();
|
|
15
|
-
// Configuration
|
|
16
|
-
let storageAccountName;
|
|
17
|
-
let connectionString;
|
|
18
|
-
/**
|
|
19
|
-
* Initializes Azure Table Storage configuration. Call once at application startup.
|
|
20
|
-
* @param config - Storage configuration options
|
|
21
|
-
* @param config.accountName - Azure Storage account name (for managed identity)
|
|
22
|
-
* @param config.connectionString - Connection string (for local development)
|
|
23
|
-
* @example
|
|
24
|
-
* // Production (Azure with managed identity)
|
|
25
|
-
* initStorage({ accountName: 'mystorageaccount' });
|
|
26
|
-
*
|
|
27
|
-
* // Local development (Azurite)
|
|
28
|
-
* initStorage({ connectionString: 'UseDevelopmentStorage=true' });
|
|
29
|
-
*/
|
|
30
|
-
function initStorage(config) {
|
|
31
|
-
storageAccountName = config.accountName;
|
|
32
|
-
connectionString = config.connectionString;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Initializes storage from environment variables.
|
|
36
|
-
* Reads STORAGE_ACCOUNT_NAME and AzureWebJobsStorage.
|
|
37
|
-
* @example
|
|
38
|
-
* initStorageFromEnv(); // Uses process.env automatically
|
|
39
|
-
*/
|
|
40
|
-
function initStorageFromEnv() {
|
|
41
|
-
initStorage({
|
|
42
|
-
accountName: process.env.STORAGE_ACCOUNT_NAME,
|
|
43
|
-
connectionString: process.env.AzureWebJobsStorage
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Checks if using Azure managed identity vs local connection string.
|
|
48
|
-
* @returns True if using managed identity (production), false for connection string (local)
|
|
49
|
-
*/
|
|
50
|
-
function useManagedIdentity() {
|
|
51
|
-
return !!storageAccountName && !connectionString?.includes('UseDevelopmentStorage');
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Gets a TableClient for the specified table, creating the table if needed.
|
|
55
|
-
* Clients are cached for reuse across requests.
|
|
56
|
-
* @param tableName - The Azure Table Storage table name
|
|
57
|
-
* @returns A configured TableClient instance
|
|
58
|
-
* @throws Error if storage is not configured
|
|
59
|
-
* @example
|
|
60
|
-
* const client = await getTableClient('users');
|
|
61
|
-
* await client.createEntity({ partitionKey: 'pk', rowKey: 'rk', name: 'John' });
|
|
62
|
-
*/
|
|
63
|
-
async function getTableClient(tableName) {
|
|
64
|
-
// Return cached client if available
|
|
65
|
-
const cached = tableClients.get(tableName);
|
|
66
|
-
if (cached) {
|
|
67
|
-
return cached;
|
|
68
|
-
}
|
|
69
|
-
let client;
|
|
70
|
-
if (useManagedIdentity()) {
|
|
71
|
-
// Azure: Use managed identity
|
|
72
|
-
const credential = new identity_1.DefaultAzureCredential();
|
|
73
|
-
const endpoint = `https://${storageAccountName}.table.core.windows.net`;
|
|
74
|
-
client = new data_tables_1.TableClient(endpoint, tableName, credential);
|
|
75
|
-
}
|
|
76
|
-
else if (connectionString) {
|
|
77
|
-
// Local/Azurite: Use connection string
|
|
78
|
-
client = data_tables_1.TableClient.fromConnectionString(connectionString, tableName);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
throw new Error('Storage not configured. Set STORAGE_ACCOUNT_NAME or AzureWebJobsStorage.');
|
|
82
|
-
}
|
|
83
|
-
// Create table if it doesn't exist
|
|
84
|
-
try {
|
|
85
|
-
await client.createTable();
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
// Ignore "table already exists" errors (409 Conflict)
|
|
89
|
-
const tableError = error;
|
|
90
|
-
if (tableError.statusCode !== 409) {
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// Cache and return
|
|
95
|
-
tableClients.set(tableName, client);
|
|
96
|
-
return client;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Clears the TableClient cache. Primarily useful for testing.
|
|
100
|
-
* @example
|
|
101
|
-
* afterEach(() => {
|
|
102
|
-
* clearTableClientCache();
|
|
103
|
-
* });
|
|
104
|
-
*/
|
|
105
|
-
function clearTableClientCache() {
|
|
106
|
-
tableClients.clear();
|
|
107
|
-
}
|
package/dist/storage/index.d.ts
DELETED
package/dist/storage/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateRowKey = exports.clearTableClientCache = exports.getTableClient = exports.useManagedIdentity = exports.initStorageFromEnv = exports.initStorage = void 0;
|
|
4
|
-
var client_1 = require("./client");
|
|
5
|
-
Object.defineProperty(exports, "initStorage", { enumerable: true, get: function () { return client_1.initStorage; } });
|
|
6
|
-
Object.defineProperty(exports, "initStorageFromEnv", { enumerable: true, get: function () { return client_1.initStorageFromEnv; } });
|
|
7
|
-
Object.defineProperty(exports, "useManagedIdentity", { enumerable: true, get: function () { return client_1.useManagedIdentity; } });
|
|
8
|
-
Object.defineProperty(exports, "getTableClient", { enumerable: true, get: function () { return client_1.getTableClient; } });
|
|
9
|
-
Object.defineProperty(exports, "clearTableClientCache", { enumerable: true, get: function () { return client_1.clearTableClientCache; } });
|
|
10
|
-
var keys_1 = require("./keys");
|
|
11
|
-
Object.defineProperty(exports, "generateRowKey", { enumerable: true, get: function () { return keys_1.generateRowKey; } });
|
package/dist/storage/keys.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate a unique row key from an identifier string
|
|
3
|
-
* Uses SHA-256 hash for consistent, URL-safe keys
|
|
4
|
-
*
|
|
5
|
-
* @param identifier - The string to hash (e.g., subscription endpoint, user ID)
|
|
6
|
-
* @returns A 32-character hex string suitable for Azure Table Storage row keys
|
|
7
|
-
*/
|
|
8
|
-
export declare function generateRowKey(identifier: string): string;
|
package/dist/storage/keys.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateRowKey = generateRowKey;
|
|
4
|
-
const crypto_1 = require("crypto");
|
|
5
|
-
/**
|
|
6
|
-
* Generate a unique row key from an identifier string
|
|
7
|
-
* Uses SHA-256 hash for consistent, URL-safe keys
|
|
8
|
-
*
|
|
9
|
-
* @param identifier - The string to hash (e.g., subscription endpoint, user ID)
|
|
10
|
-
* @returns A 32-character hex string suitable for Azure Table Storage row keys
|
|
11
|
-
*/
|
|
12
|
-
function generateRowKey(identifier) {
|
|
13
|
-
return (0, crypto_1.createHash)('sha256').update(identifier).digest('hex').substring(0, 32);
|
|
14
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared types for pwa-core
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Standard result type for operations that can fail.
|
|
6
|
-
* Used consistently across all modules (auth, push, client).
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* // Success
|
|
10
|
-
* { ok: true, data: user }
|
|
11
|
-
*
|
|
12
|
-
* // Failure
|
|
13
|
-
* { ok: false, error: 'Token expired' }
|
|
14
|
-
*
|
|
15
|
-
* // With status code (HTTP/push operations)
|
|
16
|
-
* { ok: false, error: 'Subscription expired', statusCode: 410 }
|
|
17
|
-
*/
|
|
18
|
-
export interface Result<T> {
|
|
19
|
-
ok: boolean;
|
|
20
|
-
data?: T;
|
|
21
|
-
error?: string;
|
|
22
|
-
statusCode?: number;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Creates a success result with data.
|
|
26
|
-
* @param data - The success payload
|
|
27
|
-
* @returns A Result with ok=true and the provided data
|
|
28
|
-
* @example
|
|
29
|
-
* return ok({ user: 'john', role: 'admin' });
|
|
30
|
-
*/
|
|
31
|
-
export declare function ok<T>(data: T): Result<T>;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a success result with no data.
|
|
34
|
-
* @returns A Result with ok=true and no data
|
|
35
|
-
* @example
|
|
36
|
-
* return okVoid(); // { ok: true }
|
|
37
|
-
*/
|
|
38
|
-
export declare function okVoid(): Result<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a failure result with an error message.
|
|
41
|
-
* @param error - The error message
|
|
42
|
-
* @param statusCode - Optional HTTP status code for API/push operations
|
|
43
|
-
* @returns A Result with ok=false and the error details
|
|
44
|
-
* @example
|
|
45
|
-
* return err('Token expired');
|
|
46
|
-
* return err('Subscription gone', 410);
|
|
47
|
-
*/
|
|
48
|
-
export declare function err<T>(error: string, statusCode?: number): Result<T>;
|
package/dist/types.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Shared types for pwa-core
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ok = ok;
|
|
7
|
-
exports.okVoid = okVoid;
|
|
8
|
-
exports.err = err;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a success result with data.
|
|
11
|
-
* @param data - The success payload
|
|
12
|
-
* @returns A Result with ok=true and the provided data
|
|
13
|
-
* @example
|
|
14
|
-
* return ok({ user: 'john', role: 'admin' });
|
|
15
|
-
*/
|
|
16
|
-
function ok(data) {
|
|
17
|
-
return { ok: true, data };
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Creates a success result with no data.
|
|
21
|
-
* @returns A Result with ok=true and no data
|
|
22
|
-
* @example
|
|
23
|
-
* return okVoid(); // { ok: true }
|
|
24
|
-
*/
|
|
25
|
-
function okVoid() {
|
|
26
|
-
return { ok: true };
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Creates a failure result with an error message.
|
|
30
|
-
* @param error - The error message
|
|
31
|
-
* @param statusCode - Optional HTTP status code for API/push operations
|
|
32
|
-
* @returns A Result with ok=false and the error details
|
|
33
|
-
* @example
|
|
34
|
-
* return err('Token expired');
|
|
35
|
-
* return err('Subscription gone', 410);
|
|
36
|
-
*/
|
|
37
|
-
function err(error, statusCode) {
|
|
38
|
-
return statusCode !== undefined
|
|
39
|
-
? { ok: false, error, statusCode }
|
|
40
|
-
: { ok: false, error };
|
|
41
|
-
}
|